how to run async batch job in batch-int:job-launching-gateway?

Firstly thanks for attention,

I combined spring integration and spring batch in my project, i want to launch jobs in asynchronous mode in batch-int:job-launching-gateway, my means is that each message in input channel launch job in asynchronous and not wait util to complete the jobs,my code is:

 <batch-int:job-launching-gateway request-channel="outboundJobRequestChannel"
                                     reply-channel="jobLaunchReplyChannel"/>

Update:

Thanks for @Nenad for help me, i defined JobRepository and JobLauncher in my configuration as bellow code :

@Bean
    public MapJobRepositoryFactoryBean jobRepositoryFactoryBean() {
        MapJobRepositoryFactoryBean fb = new MapJobRepositoryFactoryBean();
        return fb;
    }
 @Bean
    public JobLauncher jobLauncher() throws Exception {
        final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
        jobLauncher.setJobRepository(jobRepositoryFactoryBean().getObject());
        final SimpleAsyncTaskExecutor simpleAsyncTaskExecutor = new SimpleAsyncTaskExecutor();
        jobLauncher.setTaskExecutor(simpleAsyncTaskExecutor);
        return jobLauncher;
    }

but not worked ,and thrown bellow exception:

Exception in thread "SimpleAsyncTaskExecutor-20" java.lang.NullPointerException
    at org.springframework.batch.core.repository.dao.MapJobExecutionDao.synchronizeStatus(MapJobExecutionDao.java:158)
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:161)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy18.update(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy18.update(Unknown Source)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:351)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
    at java.lang.Thread.run(Thread.java:745)

Answers


It might be easier to simply change outboundJobRequestChannel to an ExecutorChannel. See the documentation and here.


JobLaunchingMessageHandler is using JobLauncher to launch jobs upon receiving JobLaunchRequest. You can define in configuration your JobLauncher as:

@Bean
public JobLauncher jobLauncher() {
    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    final SimpleAsyncTaskExecutor simpleAsyncTaskExecutor = new SimpleAsyncTaskExecutor();
    jobLauncher.setTaskExecutor(simpleAsyncTaskExecutor);
    return jobLauncher;
 }

And that job launcher will be injected and used for launching jobs which will result in async launching.


Need Your Help

Best way to generate both "free/demo" and commercial apps from the same source code?

iphone cocoa-touch app-store

I would like to provide two different versions of my iPhone app on the App Store -- one free that is limited by the number of items displayed through the application, and another one completely unl...

Location of the ASP.NET Cache

asp.net caching iis-7

How/where is the ASP.NET cache managed in IIS 7? I know that it's stored in the server's memory, but what is the process that manages it? Is it in the address space of w3wp.exe, or is it in another