spring batch remains in EXECUTING

本秂侑毒 提交于 2020-01-03 05:23:11

问题


I created a job which uses reader of type org.springframework.batch.item.database.HibernateCursorItemReader to execute a query.

The problem is database connection in this case is hitting connection limit (I have a oracle error ORA-12519, TNS:no appropriate service handler found) and, surprisingly, I noticed exit_code=EXECUTING and status=STARTED on BATCH_STEP_EXECUTION table.

If I run again the job it will respond "A job execution for this job is already running" and if I issue -restart on this task, it complains with message "No failed or stopped execution found for job".

How does spring batch manages these fatal failure situations? Do I have to remove these execution information manually or is there a reset option? Thank you for any help


回答1:


the current release of Spring Batch (2.2.0) doesn't appear to have an out of the box solution for this situation. as discussed in this question, 'manual' intervention in the database may be required. alternatively, if this is a particular job that is hanging (that is, you know the job name), you can do the following as well;

  • use the JobExplorer.findRunningJobExecutions(jobName)
  • go through the list of executions and 'fail' them (JobExecution.upgradeStatus(BatchStatus.FAILED))
  • save the change using JobRepository.update(jobExecution)



回答2:


Just an FYI why this problem of connection limit occurs when using a CursorItemReader (JDBCCursorItemReader or HibernateCursorItemReader)

The cursorItemReader opens a separate connection even if there is already a connection opened for the transaction (Reader -> Processors -> Writer). So, each step execution needs two connections even if it is in a single transaction and hitting the same db. This causes the connection bottleneck and so the number of db connections should be double the number of threads configured in thread pool to execute the steps in parallel. This can also be resolve if you provide a separate connection to your CursorReader.

JdbcPagingItemReader is another implementation of ItemReader which uses the same connection opened for the transaction.



来源:https://stackoverflow.com/questions/17348062/spring-batch-remains-in-executing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!