Dave,
Thanks for the reply and the suggestion to use a JobStep.
However, the way I am determining the granularity of my jobs and steps is that restartable units are deemed as 'jobs' because those are what are exposed by the JobOperator class, not the JobSteps.
So given that I have to be able to restart/stop these units, the only option I have is to spawn jobs, not steps.
As you pointed out there is a setTransactionalAttribute() method on TaskletStep. But that will not help as I was looking for a similar API on the Job interface instead.
Here is the code that I am trying and failing with the "Transaction already started... set the @Transactional annotation on the client.." issue.
Code:
public class SplitFilesTasklet implements Tasklet {
//jobRepository and jobLauncher are injected
//Tried setting TransactionalAttribute as below but that doesn't help
//@Transactional(propagation = Propagation.SUPPORTS)
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
parameters.put("timestamp", new JobParameter(new Date().getTime()));
SimpleJob job = null;
for (int i = 0; i < 5; i++) {
job = new SimpleJob("test-" + i);
TaskletStep taskletStep = new TaskletStep();
taskletStep.setName("step");
taskletStep.setJobRepository(jobRepository);
taskletStep.setTransactionManager(transactionManager);
Tasklet tasklet = new SingleFileTasklet();
taskletStep.setTasklet(tasklet);
job.addStep(taskletStep);
job.setJobRepository(jobRepository);
JobExecution jobExecution = jobLauncher.run(job,parameters);
}
}
}
The above code is in a class called SplitFilesTasklet that is itself configured to be launched using the SimpleAsynchExector and a QuartzScheduler.
When the jobLauncher attempts to launch the job above, it issues the exception.
Thanks!