java - How to run spring-batch jobs threadpooled? -
i'm starting spring-batch
jobs using joblauncher.run()
. question: how can threadpool invocations? eg maximum of 4 job threads may running concurrently, , further jobs queued?
@autowired private jobregistry registry; @autowired private joblauncher launcher; job job = registry.getjob("jobname"); launcher.run(job, params); //immediately starts job
you can set threadpooltaskexecutor task executor used simplejoblauncher (the class launches jobs). executor has properties can set, maxpoolsize.
public joblauncher createjoblauncher() { threadpooltaskexecutor taskexecutor = new threadpooltaskexecutor(); taskexecutor.setcorepoolsize(4); taskexecutor.setmaxpoolsize(4); taskexecutor.afterpropertiesset(); simplejoblauncher launcher = (simplejoblauncher) super.createjoblauncher(); launcher.settaskexecutor(taskexecutor); return launcher; }
Comments
Post a Comment