Quick explanation
For a project I am involved with, created in GWT 2.7 using Eclipse Luna as IDE, in our server code we have a connection pool (backend is a mariadb database) configured with Hikari (http://brettwooldridge.github.io/HikariCP/). This all works fine, except for one thing..
The problem
To avoid our database server (ubuntu) from exploding, I have implemented a shutdown hook like:
public void addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
dataSource.shutdown();
}
});
}
Ideally handling the cleaning of the connections held in the connection pool. What I have noticed however, when shutting down SDM by clicking the Terminate button in eclipse, is that dataSource.shutdown(); never gets called, probably because the server is not being gracefully shutdown.
The above seems to result (I do not have enough linux (in combination with mariadb) knowledge to find out if this is true, but it seems most logical to me) to eventually make the server extremely slow, and eventually exhaust its resources. So my assumption is that the server keeps the connections alive, they stack up n times untill the resources are no longer available and the server explodes.
The question
How can I clean up these resources properly using SDM? Or should I not use connection pooling during development, and only use it in an acceptance/production environment?
Thanks for your timeb
Several things:
you should use the webapp lifecycle rather than JVM lifecycle. Use a ServletContextListener
rather than a shutdown hook.
this is an Eclipse issue, it always force-terminates processes, bypassing shutdown hooks. Once you use a servlet context listener, try reloading the webapp before killing the process.
That said, I'd find it strange if that's your problem: killing the process should close all connections, releasing resources on the server (otherwise, that'd be a server bug if you ask me)