I have a simple task which has 2 jobs. When I run the task Job 1 and Job 2 run one after another. How can I configure it in a way so that when I pass the job name only that job runs?
Asked
Active
Viewed 1,334 times
1
-
Is there something preventing you from having one task for job1 and another task for job2? This would solve your problem by design. Now to answer your question, see my answer. Hope it helps. – Mahmoud Ben Hassine Sep 10 '18 at 10:44
-
Actually currently we are using spring batch admin. We have about 130 jobs. And we create jars which contain 10-20 jobs in one jar. We have configured them via XML. We are planning to remove the schedulers and convert them into tasks. Any suggestions? Thanks – Siddhant Sorann Sep 11 '18 at 11:35
1 Answers
2
By default, Spring Boot executes all jobs in the application context at startup (See here). If you want to execute only one job, you need to specify its name using the spring.batch.job.names
property.
In your case, you can add a task argument and specify which job want to run. For example: if your task contains two jobs job1
and job2
, you can add the task argument --spring.batch.job.names=job1
to run only job1
:
Make sure to add --
to the key. The command that will be executed by SCDF server should be something like:
2018-09-10 12:23:45.932 INFO 57560 --- [nio-9393-exec-1] o.s.c.d.spi.local.LocalTaskLauncher : Command to be executed: java -jar myjob.jar --spring.batch.job.names=job1 --spring.cloud.task.executionid=1
With this argument, only job1
should be executed.
Hope this helps.

Mahmoud Ben Hassine
- 28,519
- 3
- 32
- 50
-
Hey, Thanks a lot for this. It worked. Huge help. Also, any idea how I can order my jobs? a similar tag where i can maybe run job2 first then job1. --spring.batch.job.names=job2,job1 runs 1 first then 2 as job1 is defined before job2. Thanks. – Siddhant Sorann Sep 11 '18 at 11:34