Announcement Announcement Module
Collapse
No announcement yet.
Multiple threads of Spring batch with SQL server give unique key violation error. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple threads of Spring batch with SQL server give unique key violation error.

    The problem about spring batch, that sql server do not support sequences, hence a database table is maintained for sequence and sequences is internally managed by spring.

    Many database vendors don't support sequences. In these cases, work-arounds are used, such as the
    following for MySQL:
    CREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT NOT NULL) type=MYISAM;
    INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
    CREATE TABLE BATCH_JOB_EXECUTION_SEQ (ID BIGINT NOT NULL) type=MYISAM;
    INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
    CREATE TABLE BATCH_JOB_SEQ (ID BIGINT NOT NULL) type=MYISAM;
    INSERT INTO BATCH_JOB_SEQ values(0);

    In the above case, a table is used in place of each sequence. The Spring core class
    MySQLMaxValueIncrementer will then increment the one column in this sequence in order to give
    similar functionality.
    But the problem come when we try to start multiple threads, at that time it give unique key violation error. Any clue.

  • #2
    Interesting...
    I was looking at MySQLMaxValueIncrementer, the getNextKey() method has been synchronized.
    So, it suppose to be thread safe??

    Comment

    Working...
    X