2015-01-23 3 views
0

내가 사용하는 석영 2.2.1과 MySQL의 루게릭 병의 JDBC 저장소 후 저장하지 않고이 같은 간단한 작업이 있습니다석영 PersistJobDataAfterExecution는 실행

package foo; 

import org.quartz.*; 

@PersistJobDataAfterExecution 
@DisallowConcurrentExecution 
public class FooJob2 implements Job { 
    @Override 
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { 
     int count = (int) jobExecutionContext.getJobDetail().getJobDataMap().get("foobar"); 
     System.out.println("lala neu 3 " + count); 
     jobExecutionContext.getJobDetail().getJobDataMap().put("foobar", count++); 

    } 
} 

을 그리고 나는이 같은 작업을 예약하지만, 언제 작업 인쇄 foobar 번호가 증가하지 않습니다. 그 일이 일자리지도를 계속 지키고 있다는 것은 무엇을해야합니까?

public class TestStore { 
    public static void main(String[] args) throws SchedulerException, InterruptedException { 
     Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 
     scheduler.start(); 

     JobDataMap data = new JobDataMap(); 
     data.put("foobar", 12); 
     // data.put("foobar", "12"); 

     // define the job and tie it to our HelloJob class 
     JobDetail job = newJob(FooJob2.class) 
       .withIdentity("job6", "group1") 
       .storeDurably() 
       .usingJobData(data) 
       .build(); 

     // Trigger the job to run now, and then repeat every 40 seconds 
     Trigger trigger = newTrigger() 
       .withIdentity("trigger6", "group1") 
       .startNow() 
       //.usingJobData(data) 
       .withSchedule(simpleSchedule() 
         .withIntervalInSeconds(1) 
         .repeatForever()) 
       .build(); 


     // Tell quartz to schedule the job using our trigger 
     Set<Trigger> triggers = new HashSet<>(); 
     triggers.add(trigger); 
     try { 
      scheduler.scheduleJob(job, trigger); 
     } catch (SchedulerException se) { 
      System.out.println("update job"); 
      scheduler.addJob(job, true); 
     } 


     // Thread.sleep(6000); 
     // scheduler.shutdown(); 
    } 
} 

답변

3

라인에서 사용 ++count.

jobExecutionContext.getJobDetail().getJobDataMap().put("foobar", ++count);