0

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

Joey Roosing
  • 2,145
  • 5
  • 25
  • 42
  • 1
    *During development* with Eclipse, you might also try running with ``minimumIdle=0`` and ``idleTime=30000`` (30 seconds), so generally there won't be many (or any) connections sitting in the pool -- they'll be mostly created on-demand. – brettw Feb 21 '15 at 10:24

1 Answers1

2

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)

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for the lead. I will get on it soon! Hooking up to the webapp lifecycle makes alot more sense then on a jvm life cycle. As for the last bit, I can not verify whether it actually closes the resources, Ill have to spend some time playing with the server. – Joey Roosing Feb 18 '15 at 17:29
  • Hey, just getting back at you letting know the result. You gave me some good pointers that ultimately led to a cleaner solution then what I had. Thanks for that! Although eclipse will continue to be a pain, using some tricks as you perscribed does the trick. – Joey Roosing Feb 19 '15 at 19:30