Skip to content

Intermittent OptimisticLockingFailureException when starting job using jobOperator.start() with asyncTaskExecutor #5106

@scottgongsg

Description

@scottgongsg

Bug description
Intermittent OptimisticLockingFailureException when starting job using jobOperator.start() with asyncTaskExecutor

Environment
Spring Boot 4.0.0
Spring Batch 6.0.0
Java 21

Steps to reproduce

  1. Create a new Spring Boot project through the Initializr with Spring Batch and Spring Data Jpa selected.
  2. Create a configuration class and annotate it with @EnableBatchProcessing and @EnableJdbcJobRepository
  3. Implement a simple job and create jobOperator using asyncTaskExecutor
  4. Using jobOperator.start() to start the job
  5. Intermittent OptimisticLockingFailureException happend in the JdbcJobExecutionDao.updateJobExecution()
  6. Based on my debug, I found that Job instance is not inserted in the BATCH_JOB_EXECUTION table sometimes but job execution is launched in a new Thread using the asyncTaskExecutor (this is in the TaskExecutorJobLauncher class), and unable to find the job execution record in table then OptimisticLockingFailureException is happend.

Expected behavior
Job should run without issue always.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions