I have a Spring Batch application in which I want to schedule calls for jobs.
The scheduling interval is not even known in the construction so I can not comment on my job @ Scheduled.This led me to use a ThreadPoolTaskScheduler.
The talk method schedule takes a runnable as a parameter. Is it possible to schedule work in this way? I can work directly from the following service, but I can not schedule it.
This is the background of my problem, I tried to simplify it:
@ Service Public Class Scheduled Processors {Private Final Threadpold Task Scheduler Thread Paul Task Scheduler; Personal application application; @Autowired Public ScheduledProcessor (ThreadPoolTaskScheduler threadPoolTaskScheduler, application application) {this.threadPoolTaskScheduler = threadPoolTaskScheduler; This.application = application; Scheduled Tasks = new Arrayists (); Trigger trigger = new chronograph ("0/6 * * * * *"); // Here I am trying to schedule my work // The following line is wrong because a job can not be put in the runnable, but I wanted to show the desired behavior Threadpooltask scheduler Scheduling application (IMPORTUUSERGAB, TRIGGER); System.out.println ("Job launch!"); } JobBuilderFactory is here: @Bean Public Job importUserJob (JobBuilderFactory Employment, Phase S1, Phase S2) {return jobs.get (" ImportUserJob ") .increator (new run indicator ()). Flow (S1) .end () .build (); }
I understand (well, I'm not even sure about it) that I can not hire a straight runner, but is it possible to change it in any way ? Or can you advise me to be able to dynamically schedule the Spring Batch jobs?
If something changes, then I should be able to start / quit my steps, as I can currently with threadPoolTaskScheduler.
If you can thank or give a tip for any help.
I created a square that increases the number of runnables (and for convenience, which is the thread Applies to avoid the need to implement all runner classes.)
@Component Public Class MyRunnableJob implements the Runnable {Private Job Job; Personal Job Parameters Job Parameters; Private Final Joboperator Joinupator; @ Owned Public MyRunnableJob (Job Manager Job) {this.jobOperator = jobOperator; } Public Zero Set job (job job) {this.job = job; } @ Override Public Wide Run (try {string dateParam = new date () ToString (); This.jobParameters = New JobParametersBuilder () AddString ("date", dateParam) .toobParameters (); System.out.println ("Job Name:" + job.getName () + "on" + Date Param); JobOperator.start (job.getName ()), JobPaymetretroststring ()); } Hold (NoSuchJobException | JobInstanceAlreadyExistsException | JobParametersInvalidException pre) {Logger.getLogger (MyRunnableJob.class.getName ()) Log in (Level.SEVERE, null, ex). }}}
In my scheduled processor class, I set up a job for my class in class and then pass it as the parameter of the schedule method.
public class scheduling processor {// Autoward Field: Private Final Job Launcher Job Launcher; Private Last Job Import User Job; Personal Finals Threadpold Task Scheduler Thread Poltask Scheduler; Personal Finals MyRunnableJob myRunnableJob; // Other Field: Private List & lt; Scheduled Future & gt; scheduled task; @Autowired Public SchedulingProcessor (JobLauncher jobLauncher, Job importUserJob, ThreadPoolTaskScheduler threadPoolTaskScheduler, MyRunnableJob myRunnableJob) throws an exception {this.jobLauncher = jobLauncher; This.importUserJob = importUserJob; This.threadPoolTaskScheduler = threadPoolTaskScheduler; This.myRunnableJob = myRunnableJob; Trigger trigger = new chronograph ("0/6 * * * * *"); MyRunnableJob.setJob (this.importUserJob); Scheduled Tasks = new Arrayists (); Scheduled Tasks.add (this.threadPoolTaskScheduler.schedule (runable) myRunnableJob, Trigger)); }}
The scheduled task list is just to control the tasks that I have defined.
By this move I was dynamically enabled (Thanks to Thunderpool Task Scheduler ) Explained in the class implementing Spring Batch Jobs Rungele. I believe it can help me in the same case as someone.
No comments:
Post a Comment