title: Deadlock while running multiple instances of a spring batch job
body: <p>I have a spring batch job that reads from a database and writes into a file after doing some processing, in a chunk based step.
  My requirement is to run almost 16 instances of the job parallelly at the same time, just <strong>with different job parameters.</strong></p>
  <p>But I've been facing the a couple of issues while doing so.</p>
  <p>1.</p>
  <blockquote>
  <p>Could not open JDBC Connection for transaction. Nested exception is java.sql.SQLTransientConnectionException: Hikaripool -1 - Connection is not available.</p>
  </blockquote>
  <ol start="2">
  <li></li>
  </ol>
  <blockquote>
  <p>Exception: could not increment identity. Nested Exception is com.microsoft.SQLserver.jdbc.SQLServerException: Transaction (process ID 124) was deadlocked on lock resources with other process, and has been chosen as the deadlock victim. Rerun the transaction.</p>
  </blockquote>
  <p>I've tried the solutions provided in the link <a href="https://github.com/spring-projects/spring-batch/issues/1448#issuecomment-566278146" rel="nofollow noreferrer">Github link</a>, by setting the <code>IsolationLevel</code> and altering the metadata tables as shown below.</p>
  <p>Set the IsolationLevelForCreate like this</p>
  <pre><code>JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
  factory.setIsolationLevelForCreate(&quot;ISOLATION_REPEATABLE_READ&quot;);
  </code></pre>
  <p>Have the DBA add indexes to each of the SEQ tables like this (JET is my schema that I put the repo tables in):</p>
  <pre><code>ALTER TABLE [JET].[BATCH_JOB_EXECUTION_SEQ]
  ADD CONSTRAINT [BATCH_JOB_EXECUTION_SEQ_PK] PRIMARY KEY CLUSTERED ([ID] ASC)
  GO
  
  ALTER TABLE [JET].[BATCH_JOB_SEQ]
  ADD CONSTRAINT [BATCH_JOB_SEQ_PK] PRIMARY KEY CLUSTERED ([ID] ASC)
  GO
  
  ALTER TABLE [JET].[BATCH_STEP_EXECUTION_SEQ]
  ADD CONSTRAINT [BATCH_STEP_EXECUTION_SEQ_PK] PRIMARY KEY CLUSTERED ([ID] ASC)
  GO
  </code></pre>
  <p>But I am still facing the issue.</p>
  <p>PS: The spring batch has been deployed to AKS(Azure Kubernetes Services), and using Azure SQLServer as datasource.</p>