commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Muldoon <...@firstbest.com>
Subject Re: pool - cleaning up resources on JVM exit
Date Thu, 05 Apr 2007 11:42:31 GMT
Try adding a shutdown hook. e.g.

    new ShutdownHook().register();

    /**
     * Provides a shutdown hook for shutting down the pool.
     */
    private class ShutdownHook extends Thread {
        /**
         * Registers this hook for invocation during shutdown.
         */
        public void register() {
            Runtime.getRuntime().addShutdownHook(this);
        }

        /**
         * Closes the pool and each of the objects within it.
         */
        public void run() {
            try {
                // Do something.
            }
            catch (Exception e) {
                throw new SystemException(e);
            }
        }
    }


Conrad CRAMPTON PSE 52704 wrote:
> Hi,
> Is there anyway of clearing up resources from a GenericObjectPool when
> the JMV closes (crashes)? I have objects that maintain a connection to a
> service that need to be closed when the web server is restarted or
> crashes.
> Also, if an object is borrowed from the pool and isn't returned because
> of interruption in the web application flow or some other reason, does
> it get 'swept up' by the evictor thread eventually or is there some
> other way of returning this to the pool or simply just destroying it for
> it to be recreated in the pool when necessary?
>  
> Thanks for your consideration
> Conrad
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message