2016-04-09 20 views
1

2分ごとにcron式がトリガーされると、Springバッチジョブが一度起動されます。しかし、我々は、それがトリガされたときに、それが継続的に実行されることに気づいている - 最初のジョブが完了するとすぐに、副業をログに見られるように起動されます:cron式トリガー時にSpringバッチジョブを一度起動するポーラー

2016-04-08 21:18:02,426 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run() 133] - Job: [FlowJob: [name=irsDataPrepJob]] launched with the following parameters: [{subscriberReaderType=originalSubscriberReaderType, time=1460175480034}] 
2016-04-08 21:18:03,095 INFO [xxx.batch.listener.IrsJobExecutionListener.beforeJob() 41] - Started jobName=[irsDataPrepJob], jobId=[99018], jobParameters={subscriberReaderType=originalSubscriberReaderType, time=1460175480034}] 
2016-04-08 21:18:05,738 INFO [org.springframework.batch.core.job.SimpleStepHandler.handleStep() 146] - Executing step: [generateIrsData] 
. 
. 
. 
2016-04-08 21:18:15,264 INFO [xxx.batch.listener.IrsJobExecutionListener.afterJob() 54] - Finished jobName=[irsDataPrepJob], jobId=[99018], with status=[COMPLETED], jobParameters={subscriberReaderType=originalSubscriberReaderType, time=1460175480034}] 
2016-04-08 21:18:15,929 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run() 136] - Job: [FlowJob: [name=irsDataPrepJob]] completed with the following parameters: [{subscriberReaderType=originalSubscriberReaderType, time=1460175480034}] and the following status: [COMPLETED] 
2016-04-08 21:18:15,933 INFO [org.springframework.integration.handler.LoggingHandler.handleMessageInternal() 155] - JobExecution: id=99282, version=2, startTime=Fri Apr 08 21:18:02 PDT 2016, endTime=Fri Apr 08 21:18:15 PDT 2016, lastUpdated=Fri Apr 08 21:18:15 PDT 2016, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=99018, version=0, Job=[irsDataPrepJob]], jobParameters=[{subscriberReaderType=originalSubscriberReaderType, time=1460175480034}] 
2016-04-08 21:18:17,826 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run() 133] - Job: [FlowJob: [name=irsDataPrepJob]] launched with the following parameters: [{subscriberReaderType=originalSubscriberReaderType, time=1460175495933}] 

我々はこのようなcronの表現を持っています:

batch.job.schedule.cron.irsDataPrepJobRunner=0 0/2 * * * * 

そして、我々のJavaConfig Beanには、次のようになります。

@Configuration 
@EnableIntegration 
@IntegrationComponentScan 
public class IrsJobIntegration { 

@Autowired 
private ApplicationContext appContext; 

@Bean 
MessageChannel control() { 
    return new DirectChannel(); 
} 

@Bean 
@ServiceActivator(inputChannel="irsControl") 
public ExpressionControlBusFactoryBean irsControlBus() { 
    return new ExpressionControlBusFactoryBean(); 
} 

@Bean 
@InboundChannelAdapter(value = "irsDataPrepJobInputChannel", poller = @Poller(cron="${batch.job.schedule.cron.irsDataPrepJobRunner}")) 
public MessageSource<JobLaunchRequest> pollIrsDataPrepJob() { 

    return new MessageSource<JobLaunchRequest>() { 

     @Override 
     public Message<JobLaunchRequest> receive() { 
      return new GenericMessage<JobLaunchRequest>(requestIrsDataPrepJob()); 
     } 

    }; 
} 

@Transformer(inputChannel="irsDataPrepJobInputChannel",outputChannel="irsDataPrepJobOutputChannel") 
public JobLaunchRequest requestIrsDataPrepJob() { 
    JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); 
    jobParametersBuilder.addString("subscriberReaderType", "originalSubscriberReaderType").addLong("time",System.currentTimeMillis()); 
    return new JobLaunchRequest((Job) appContext.getBean("irsDataPrepJob"), jobParametersBuilder.toJobParameters()); 
} 

アプリケーションコンテキストのように定義チャネルを有し10

<int:channel id="irsDataPrepJobInputChannel"/> 
<int:channel id="irsDataPrepJobOutputChannel"/> 
<int:channel id="irsDataPrepJobJobLaunchReplyChannel"/> 
<batch-int:job-launching-gateway request-channel="irsDataPrepJobOutputChannel" 
           reply-channel="irsDataPrepJobJobLaunchReplyChannel"/> 
<int:logging-channel-adapter channel="irsDataPrepJobJobLaunchReplyChannel"/> 

答えて

1

@Pollerには、maxMessagesPerPollという要素があります。 maxMessagesPerPoll = "1"の場合は、そのトリックが実行されました。

@Bean 
@InboundChannelAdapter(value = "irsDataPrepJobInputChannel", poller = @Poller(cron="${batch.job.schedule.cron.irsDataPrepJobRunner}", maxMessagesPerPoll="1")) 
public MessageSource<JobLaunchRequest> pollIrsDataPrepJob() { 

    return new MessageSource<JobLaunchRequest>() { 

     @Override 
     public Message<JobLaunchRequest> receive() { 
      return new GenericMessage<JobLaunchRequest>(requestIrsDataPrepJob()); 
     } 

    }; 
} 
+0

あなた自身で把握していることを嬉しく思います!もちろん、あなた自身の答えを受け入れることができます –

関連する問題