Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:01:02+00:00 2026-05-27T23:01:02+00:00

I have a spring batch quartz set up. I have two jobs configured and

  • 0

I have a spring batch quartz set up. I have two jobs configured and running in parallel. The jobs are reading a file and then writing some data to the db. Here is the tricky part, the file names are calculated within the beforeJob() method of my execution listener. After each job finishes, the afterJob() would then calculate the next fileName. File names have the following pattern xxxxxx.nnnn where nn.. are numbers and sometimes the sequence can have numbers missing, therefore I am attempting “jump” over those missing passages and when I find an existing number to launch the job.
I want to know if it’s possible to restrict the number of jobs launched each time the cron trigger fires? I want to have a single job launched after a chron trigger fires.

For example:

  1. At 12.30 PM the job is launched.
  2. The job tries to find the correct file
  3. The job fails with FileNotFound ( which is configured as a non -skippable exception)
  4. After the job, the fileName counter is incremented

Right now, when the trigger fires, I get like 4 or more jobs of the same type being executed asynchronously. In my batch set-up I have two <jobs> configured to launch one after the other each hour within a 5 minutes interval of one another. The jobs both fallow the flow provided in the example. In conclusion : Is it possible to launch a single job after a cron trigger fires and have both job types run in parallel.

Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:01:03+00:00Added an answer on May 27, 2026 at 11:01 pm

    Your job should know what file to process before it is executed. E.g. the file name should be passed as job parameter. Remove JobExecutionListener and add StepExecutionListener to access job parameters via StepExecution#getJobParameters(). One job = one file.

    Now from your scheduler you want to make sure that only one job is run at one point of time. You can achieve this in two ways:

    • Using the async task executor. In this case each time you launch the job, it will not be executed in a background (unless your scheduler does not fire timer events each time in new thread).

    <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
        <property name="taskExecutor" ref="taskExecutor" />
    </bean>
    
    <bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
    

    • If you use the same job launcher for other jobs, which need to be executed in background, you need to use ThreadPoolTaskExecutor but you can manually check if the job is running:

    for (final JobInstance jobInstance : jobExplorer.getJobInstances(jobName(), 0, LOOK_BEHIND_INSTANCES)) {
        for (final JobExecution jobExecution : jobExplorer.getJobExecutions(jobInstance)) {
            final BatchStatus status = jobExecution.getStatus();
    
            if (status.isRunning()) {
                // Ops:
                break;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I have a Spring batch program that reads a file (example file I
I have a spring batch program. The skip limit is set to 5 and
I have a file with records. I have to develop a spring batch program
I have some test classes that are making use of spring-batch, and hibernate. My
I have a spring batch program which reads from a file and writes to
I have a simple spring batch program which reads data from a INPUT file
I have several jobs in spring batch. The first job is kind of a
I'm using Spring Batch 2.1.5. I have many jobs that are very similar between
I have a property file and using Spring property place holder, I set values
I have a batch file question Set filename=C:\Documents\Example.doc I have a string %FILENAME% and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.