0

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.

Henning
  • 3,055
  • 6
  • 30
  • The `JobExecutionListener` is too early for closing the context. To help you find a better place to close it, please provide more information about your app. Are you using Spring Boot? Are you using Spring Cloud Task? Do you have the Spring Boot web starter on the classpath? If yes, then why? – Henning Aug 27 '23 at 20:47
  • Thanks for your reply. Spring Boot? - Yes Spring Cloud Task? - Yes Spring Boot web starter on the classpath - No. I also tried to add a property spring.cloud.task.closecontext_enabled = true, to close the context/jvm, when a task is successfully completed. Now the context is closed early before completetion of all process and getting below error - Failed to re-amortize loan having Error: Connection prematurely closed BEFORE response; It looks like the connection of task server jvm was closed before a response was received from other application in writer step. – Ankit Gupta Aug 31 '23 at 15:58

1 Answers1

0

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).

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • Thanks For Reply!! Yes, as far as I know, scdf task pod/jvm should be automatically terminated after the successful execution of the task. Do you suggest how can I debug my concern? Is it due to spring starters added in pom.xml? – Ankit Gupta Aug 31 '23 at 15:55