我正在使用Spring Boot v2.2.6.RELEASE和Spring Batch示例。我有3个按顺序运行的Jobs。在第三份工作中,我使用了AsyncItemProcessor
和AsyncItemWriter
。执行此批处理作业时,始终会出现以下错误。
我们如何解决此问题?
HikariPool-1-连接oracle.jdbc.driver.T4CConnection@538a3107由于SQLSTATE(08006),ErrorCode(17002)被标记为断开
代码:
@Configuration
public class CountryBatchConfig {
.......
@Autowired
@Qualifier(value="oracleDS")
private DataSource dataSource;
@Bean(destroyMethod = "")
@StepScope
public JdbcCursorItemReader<Employee> EmployeeReader() throws Exception {
JdbcCursorItemReader<Employee> reader = new JdbcCursorItemReader<>();
reader.setDataSource(this.dataSource);
reader.setSql(SELECT_Employee_SQL);
reader.setRowMapper(new EmployeeRowMapper());
reader.afterPropertiesSet();
return reader;
}
@Bean
public ItemProcessor<Employee, Employee> EmployeeProcessor() {
return new EmployeeProcessor();
}
@Bean
public AsyncItemProcessor<Employee, Employee> asyncItemProcessor() throws Exception{
AsyncItemProcessor<Employee, Employee> asyncItemProcessor = new AsyncItemProcessor<>();
asyncItemProcessor.setDelegate(EmployeeProcessor());
asyncItemProcessor.setTaskExecutor(new SimpleAsyncTaskExecutor());
asyncItemProcessor.afterPropertiesSet();
return asyncItemProcessor;
}
@Bean
public EmployeeWriter EmployeeWriter() {
return new EmployeeWriter();
}
@Bean
public AsyncItemWriter<Employee> asyncItemWriter() throws Exception{
AsyncItemWriter<Employee> asyncItemWriter = new AsyncItemWriter<>();
asyncItemWriter.setDelegate(EmployeeWriter());
asyncItemWriter.afterPropertiesSet();
return asyncItemWriter;
}
}
错误:
org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [SELECT XXXXXXXX]; IO Error: Connection reset; nested exception is java.sql.SQLRecoverableException: IO Error: Connection reset
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:254) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1444) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:700) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:712) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:763) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:844) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at com.SubdivisionDao.getSubDivisionByCountryId(SubdivisionDao.java:27) ~[classes/:na]
at com.processor.EmployeeProcessor.process(EmployeeProcessor.java:49) ~[classes/:na]
at com.processor.EmployeeProcessor.process(EmployeeProcessor.java:1) ~[classes/:na]
at org.springframework.batch.integration.async.AsyncItemProcessor$1.call(AsyncItemProcessor.java:102) ~[spring-batch-integration-4.1.1.RELEASE.jar:4.1.1.RELEASE]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_171]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Caused by: java.sql.SQLRecoverableException: IO Error: Connection reset
at oracle.jdbc.driver.T4CPreparedStatement.fetch(T4CPreparedStatement.java:1031) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.OracleStatement.fetchMoreRows(OracleStatement.java:3590) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.InsensitiveScrollableResultSet.fetchMoreRows(InsensitiveScrollableResultSet.java:1008) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.InsensitiveScrollableResultSet.absoluteInternal(InsensitiveScrollableResultSet.java:972) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.InsensitiveScrollableResultSet.next(InsensitiveScrollableResultSet.java:572) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at com.zaxxer.hikari.pool.HikariProxyResultSet.next(HikariProxyResultSet.java) ~[HikariCP-3.2.0.jar:na]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:679) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) ~[spring-jdbc-5.1.5.RELEASE.jar:5.1.5.RELEASE]
... 11 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210) ~[na:1.8.0_171]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_171]
at oracle.net.ns.Packet.receive(Packet.java:311) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.net.ns.DataPacket.receive(DataPacket.java:105) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:305) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:249) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:171) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.net.ns.NetInputStream.read(NetInputStream.java:89) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:426) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:390) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
at oracle.jdbc.driver.T4CPreparedStatement.fetch(T4CPreparedStatement.java:1022) ~[ojdbc7-12.1.0.1.0.jar:12.1.0.1.0]
... 20 common frames omitted
DBConfig
@Configuration
public class DBConfig {
@Autowired
private Environment env;
@Bean(name="oracleDS")
@Primary
public DataSource batchDataSource(){
return DataSourceBuilder.create()
.url(env.getProperty("spring.datasource.url"))
.driverClassName(env.getProperty("spring.datasource.driver-class-name"))
.username(env.getProperty("spring.datasource.username"))
.password(env.getProperty("spring.datasource.password"))
.build();
}
}