spring batch - Continually restating a job using JobExecutionListener -


we need job run continuously without need external scheduler. have extended jobexecutionlistener, follows:

@autowired @qualifier("myjob") private job job;  private int counter = 0;  @override public void afterjob(jobexecution jobexecution) {     jobexecution.stop();     jobparameters jobparameters = new jobparameters();    jobparameter jobparameter = new jobparameter((new integer(++counter)).tostring());    jobparameters.getparameters().put("counter", jobparameter);    try {       joblauncher.run(job, jobparameters);    }     catch (jobexecutionalreadyrunningexception e) {       throw new runtimeexception(e);    } catch (jobrestartexception e) {       throw new runtimeexception(e);    } catch (jobinstancealreadycompleteexception e) {       throw new runtimeexception(e);    } catch (jobparametersinvalidexception e) {       throw new runtimeexception(e); } 

when run, jobexecutionalreadyrunningexception thrown.

jobexecutionalreadyrunningexception: job execution job running: jobinstance: id=0, version=0, job=[myjob] 

where going wrong?

thanks

from official doc:

the shutdown not immediate, since there no way force immediate shutdown, if execution in developer code framework has no control over, such business service. however, control returned framework, set status of current stepexecution batchstatus.stopped, save it, same jobexecution before finishing.

maybe can have chance using specialized joblauncher launch job after previous job's thread termination or custom taskexecutor associated joblauncher.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -