Results 1 to 2 of 2

Thread: jdbcCursorItemReader for multiple job instances

  1. #1
    Join Date
    Mar 2011
    Posts
    6

    Default jdbcCursorItemReader for multiple job instances

    I have 5 threads in a web container scheduled to listen to DB for any requests for job execution. Job execution requests come from a UI interface. If there a two simultaneous requests to execute a job but for different criteria, these two jobs are executed simultaneously but two different threads.

    I would like to know if this is a problem, as jdbcCursorItemReader is not thread safe, will both the threads mess with the single cursor from the reader. Because, if I run a single job it runs fine. But if I schedule two jobs at the same time I get, Error Log: [Unexpected cursor position change.]

    What is a best way to handle this? Can somebody help me?
    Last edited by dgiridhar; Dec 17th, 2012 at 10:51 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    338

    Default

    A couple things to note:
    1. You are correct. JdbcCursorItemReader is <em>not</em>thread safe for that reason.
    2. Use the JdbcPagingItemReader instead in multi-threaded environments. However, do keep in mind that doing so requires you to turn off saving state (which turns off restartability).
    3. How are you launching your job? There are ways to launch a job with an independent child context. That should solve your issue assuming that it's the multiple job instances that are causing the race condition and not any multithreading within each job.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •