(A similar question here is related to Tomcat resources, not spring boot managed beans)
Two Hikari DataSource pools are being creating like this:
@Primary
@Bean(value="appDataSource",destroyMethod="close")
@ConfigurationProperties("app.db.datasource")
@Override
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(value="pacsDataSource",destroyMethod="close")
@Override
public DataSource dataSource() {
return new HikariDataSource(hikariConfig());
}
But when the application is shut down I see the below errors in the logs and the java process fails to exit. From what I can tell spring should be calling close() on those datasources, which should terminate the pool threads.
2023-04-24T11:02:24.758 [https-jsse-nio-8080-exec-2] WARN org.apache.catalina.loader.WebappClassLoaderBase - The web application [ROOT] appears to have started a thread named [HikariPool-1 housekeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.base@15.0.1/jdk.internal.misc.Unsafe.park(Native Method)
java.base@15.0.1/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:252)
java.base@15.0.1/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:1661)
java.base@15.0.1/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182)
java.base@15.0.1/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1056)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
java.base@15.0.1/java.lang.Thread.run(Thread.java:832)
2023-04-24T11:02:24.759 [https-jsse-nio-8080-exec-2] WARN org.apache.catalina.loader.WebappClassLoaderBase - The web application [ROOT] appears to have started a thread named [HikariPool-2 housekeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.base@15.0.1/jdk.internal.misc.Unsafe.park(Native Method)
java.base@15.0.1/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:252)
java.base@15.0.1/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:1661)
java.base@15.0.1/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182)
java.base@15.0.1/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1056)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1116)
java.base@15.0.1/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
java.base@15.0.1/java.lang.Thread.run(Thread.java:832)
Edit: Oddly enough I have one VM where this error does not prevent the java process from exiting. So I'm working on trying to figure out the difference. The .jar is exactly the same, but there are other environmental differences. Either way it seems like the process should exit when spring is boot shutdown.