2015-12-28 42 views
2
package org.quartz;  
import org.quartz.Scheduler;  
import org.quartz.JobDetail;  
import org.quartz.JobKey;  
import org.quartz.Trigger;  
import org.quartz.Job;  
import org.quartz.JobExecutionContext;  
import org.quartz.JobExecutionException;  
import org.quartz.SchedulerException;  
import org.quartz.impl.StdSchedulerFactory;  
import static org.quartz.JobBuilder.*;  
import static org.quartz.TriggerBuilder.*;  
import static org.quartz.SimpleScheduleBuilder.*;  
import static org.quartz.CronScheduleBuilder.*;  
import static org.quartz.CalendarIntervalScheduleBuilder.*;  
import static org.quartz.DateBuilder.*;  

class myJob implements Job {   
    public void execute(JobExecutionContext context)  
     throws JobExecutionException 
    { 
     System.out.println("Hello! HelloJob is executing."); 
    } 
} 

public class schedule{ 
    public static void main(String args[]) throws Exception{  
     System.out.println("Java working"); 

     try { 
        // Grab the Scheduler instance from the Factory     
       JobKey jobKeyA = new JobKey("myJob", "group1");  
       JobDetail jobA = JobBuilder.newJob(myJob.class)  
       .withIdentity(jobKeyA).build(); 

         // Trigger the job to run now, and then every 40 seconds 
       Trigger trigger1 = TriggerBuilder  
         .newTrigger()  
         .withIdentity("dummyTriggerName1", "group1")  
         .withSchedule(
          CronScheduleBuilder.cronSchedule("0/5 * * * * ?")) 
         .build(); 

         Scheduler scheduler = new StdSchedulerFactory().getScheduler(); 

         // and start it off  
         scheduler.start(); 

         // Tell quartz to schedule the job using our trigger 

         scheduler.scheduleJob(jobA, trigger1); 


      } catch (SchedulerException se) {     
       se.printStackTrace(); 
      }  
    }  
} 

而且我得到一个实例化作业的错误,然后显然所有作业的触发器都设置为ERROR状态。 是什么原因? 请帮助它是非常重要的。 为我提供了答案。 错误错误发生在Quartz中执行的实例化作业sheduler

[ERROR] 03年12月28日:03:30.008 PM DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.core.ErrorLogger]

时发生错误实例化作业被执行。作业= 'group1.myJob'

org.quartz.SchedulerException:问题实例化类 'org.quartz.myJob'[见嵌套异常: java.lang.IllegalAccessException:类 org.quartz.simpl。 SimpleJobFactory不能在 org.quartz访问在org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:58)类 org.quartz.myJob与修饰语 “”]

的成员

。 simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java :69)

在org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)

在 org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375) 引起: java.lang.IllegalAccessException: 类org.quartz.simpl.SimpleJobFactory不能访问类 org.quartz.myJob的成员与改性剂 “”

在sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102 )

at java.lang.Class。的newInstance(Class.java:436)

在org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)

... 3更[INFO] 03年12月28日:03:30.013 PM DefaultQuartzScheduler_QuartzSchedulerThread [org.quartz.simpl.RAMJobStore]

工作group1.myJob的所有触发器设置为错误状态。

+0

你可以添加你所得到的异常堆栈跟踪? –

+0

yups ....我给了错误例外 – striker0794

+0

请给我提供解决方案 – striker0794

回答

3

您的工作职位必须是public。否则,JobBuilder将无法读取它。

public class myJob implements Job {   
    public void execute(JobExecutionContext context) throws JobExecutionException { 
     System.out.println("Hello! HelloJob is executing."); 
    } 
} 
+0

伟大的一点:)这种愚蠢的东西造成了这么多的问题:)谢谢 – siddhusingh

0
  1. 类应该是公共类
  2. 默认的构造应该是公开的
相关问题