starten gleiche Feder Batch mehrfach in parallelen Threads erzeugt diesen Fehler:Starten gleiche Feder Batch-Job mehrere Male in parallelen Threads Batch doppelten Eintrag .spring ‚xxxxxxx‘ für Schlüssel ‚JOB_INST_UN‘
.spring batch Duplicate entry 'xxxxxxx' for key 'JOB_INST_UN'
Hier ist, wie die Jobs werden genannt:
JobParameters jobParameters = new JobParametersBuilder() .addLong("time",System.currentTimeMillis()).toJobParameters();
JobLauncher jobLauncher = (JobLauncher) ApplicationContextUtils.getApplicationContext().getBean("jobLauncher");
Job job = (Job) ApplicationContextUtils.getApplicationContext().getBean("writeTeamsToDB");
try {
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
logger.info("thread completed..");
} catch (Exception e) {
e.printStackTrace();
}
ich unten Fehlermeldung erhalten:
2016-06-01 11:15:17,385 DEBUG [org.springframework.batch.support.transaction.ResourcelessTransactionManager] - <Rolling back resourceless transaction on [org.springframework.batch.support.tra[email protected]2846ce4f]>
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)];
Duplicate entry 'writeTeamsToDB-38eb86e9d3cf1b87034c74e54d25a658' for key 'JOB_INST_UN';
nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'writeTeamsToDB-38eb86e9d3cf1b87034c74e54d25a658' for key 'JOB_INST_UN'
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:932)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.createJobInstance(JdbcJobInstanceDao.java:115)
at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:135)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:172)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy6.createJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:125)
at com.ritsasoft.fantwiz.helper.FantwizWriteTeamsHelper.run(FantwizWriteTeamsHelper.java:39)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2016-06-01 11:15:17,388 INFO [com.ritsasoft.fantwiz.helper.FantwizWriteTeamsHelper] - <launching prediction writer.....>
2016-06-01 11:15:17,388 INFO [com.ritsasoft.fantwiz.helper.FantwizWriteTeamsHelper] - <thread for new job started..>
2016-06-01 11:15:17,388 DEBUG [org.springframework.batch.support.transaction.ResourcelessTransactionManager] - <Creating new transaction with name [org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution]: PROPAGATION_REQUIRES_NEW,ISOLATION_REPEATABLE_READ>
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'writeTeamsToDB-38eb86e9d3cf1b87034c74e54d25a658' for key 'JOB_INST_UN'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:873)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:866)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:629)
... 24 more
Was tun yo Du glaubst, ich könnte verbessern/überprüfen, damit es funktioniert? Kann ich den eindeutigen Schlüssel selbst definieren, um es zu vermeiden?
Was können wir tun, um Ihnen zu helfen? Hast du http://stackoverflow.com/help/how-to-ask gelesen? Versuchen Sie, ein [MCVE] (http://stackoverflow.com/help/mcve) zu erstellen. –
kann ich bitte etwas Hilfe dabei bekommen. Vielen Dank. – jkakumanu09
danke für die Antwort J.Chomel. Ja, ich habe auf Google gesucht, aber keine Lösung gefunden. Ich benutze die unten meinen Job zu starten, – jkakumanu09