Spring batch task pod(jvm) is not automatically terminated after competition of task

107 views Asked by At

Spring batch task pod(jvm) is not automatically terminated after the competition of the task. So, I thought to close the application context explicitly post-completion of the task by closing the context in afterJob method of JobExecutionListener class.

Now context is closed on completion of job but getting some database error -

2023-08-27 18:11:59.348 [main] INFO  c.l.r.config.ApplicationShutdownHook - Application is shutting down. Performing cleanup...
2023-08-27 18:11:59.348 [main] INFO  c.l.r.config.ApplicationShutdownHook - Cleanup completed. Application is now shutting down.
2023-08-27 18:11:59.363 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown initiated...
2023-08-27 18:11:59.365 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Shutdown completed.
2023-08-27 18:11:59.366 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2023-08-27 18:11:59.427 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
2023-08-27 18:12:01.539 [main] INFO  o.s.b.c.l.support.SimpleJobLauncher - Job: [FlowJob: [name=reamortizationJob]] failed unexpectedly and fatally with the following parameters: [{run.id=125}]
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-1) has been closed.

It looks like the Hikari pool is closed prematurely and there are some Bean is trying to get a connection after the pool has been closed.

How can I solve it? Please help me to address it.

Spring batch task pod(jvm) is not automatically terminated after the competition of the task. So, I thought to close the application context explicitly post-completion of the task by closing the context in afterJob method of JobExecutionListener class.

Application context should be gracefully closed after completion of task but is is throwing error relate to HikariPool-1.

1

There are 1 answers

2
Mahmoud Ben Hassine On

The question to ask is why the application is not automatically terminated after completion. This is what I would investigate, rather than looking for a way to terminate the app explicitly.

A Spring Boot Batch application should terminate automatically after the job completion (successfully or with a failure). If this is not the case, then there is some resource preventing that (the typical example is a ThreadPoolTaskExecutor that is not automatically shutdown).