
Originally Posted by
lbo
Thanks chudak for the reply.
I did not see that there was an asychronous way of launching a batch. It can be usefull in a web app just like the example you provided.
Laurent.
You use an async executor with your job launcher:
Code:
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
This is how I launch the job in a handler coupled with my MVC layer:
Code:
Job batchJob = jobFactory.createJob();
Map<String,String> map = new HashMap<String,String>();
map.put(Constants.GUID, batch.getGuid());
map.put(Constants.UPLOAD_FILENAME, fileName);
JobParameters parameters = new JobParameters(map, new HashMap<String,Long>(), new HashMap<String,Double>(), new HashMap<String,Date>());
// Now, kick off the job
jobLauncher.run(batchJob, parameters);
Because I'm using an async executor, the call to run(...) returns immediately and I can resume the http request processing...