发生错误实例化要在Quartz sheduler

时间:2015-12-28 09:40:30

标签: java quartz-scheduler scheduler

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();
            }    
    }       
}

我收到实例化作业的错误,然后显然所有Job的触发器都设置为ERROR状态。 是什么原因? 请帮助它非常重要。 给我答案。 的错误

[ERROR] 28 Dec 03:03:30.008 PM
DefaultQuartzScheduler_QuartzSchedulerThread
[org.quartz.core.ErrorLogger]

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

org.quartz.SchedulerException: Problem instantiating class
'org.quartz.myJob'  [See nested exception:
java.lang.IllegalAccessException: Class
org.quartz.simpl.SimpleJobFactory can not access a member of class
org.quartz.myJob with modifiers ""]
    at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:58)
    at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
Caused by: java.lang.IllegalAccessException: Class
org.quartz.simpl.SimpleJobFactory can not access a member of class
org.quartz.myJob with modifiers ""
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
    at java.lang.Class.newInstance(Class.java:436)
    at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)
    ... 3 more [INFO] 28 Dec 03:03:30.013 PM
DefaultQuartzScheduler_QuartzSchedulerThread
[org.quartz.simpl.RAMJobStore]

Job group1.myJob的所有触发器都设置为ERROR状态。

3 个答案:

答案 0 :(得分:4)

您的职业等级必须为2015-12-30T10:27:29.4872452Z . 'C:\a\1\s\script.ps1' 2015-12-30T10:27:29.6780242Z Executing the following powershell script. (workingFolder = C:\a\1\s) 2015-12-30T10:27:29.6790500Z C:\a\1\s\script.ps1 2015-12-30T10:27:33.8017820Z ##[error]C:\a\1\s\script.ps1 : Some error 2015-12-30T10:27:33.8027833Z ##[error]At line:1 char:1 2015-12-30T10:27:33.8037819Z ##[error]+ . 'C:\a\1\s\script.ps1' 2015-12-30T10:27:33.8037819Z ##[error]+ ~~~~~~~~~~~~~~~~~~~~~~~ 2015-12-30T10:27:33.8047816Z ##[error] + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException 2015-12-30T10:27:33.8047816Z ##[error] + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,script.ps1 2015-12-30T10:27:33.8057887Z ##[error] 2015-12-30T10:27:33.8057887Z ##[error]Process completed with exit code 1 and had 1 error(s) written to the error stream. 。否则,JobBuilder无法读取它。

public

答案 1 :(得分:2)

  1. 班级应为公共班级
  2. 默认构造函数应该是公共的

答案 2 :(得分:0)

在上述解决方案之上进行改进。可以使用static关键字标记该类以提高效率。每次安排计划的时段发生时都会创建作业。

minimumGap()