You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Conrad CRAMPTON PSE 52704 <co...@kent.pnn.police.uk> on 2007/03/30 15:18:28 UTC

pool - cleaning up resources on JVM exit

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


Re: pool - cleaning up resources on JVM exit

Posted by Abhijit Akhawe <ab...@gmail.com>.
Not sure if finalizers will be invoked if the JVM 'crashes'. Finalizers will
work in case there is a graceful exit of JVM.

On 3/30/07, Will Pugh <wi...@sourcelabs.com> wrote:
>
> Finalizers can be a pain, but might for this scenario they might work
> for you.
>
> Sandy McArthur wrote:
> > When the JVM crashes there is no cleaning up, the JVM just exits and
> > the OS will clean up what it can. Pool cannot recover from a JVM
> > crash.
> >
> > When the JVM exits there will be a bit more clean up. Whether or not
> > it's a full clean up or something else will depend on your use of the
> > shutdown handlers. Pool does not use shutdown handlers.
> >
> > If a borrowed object isn't returned to the pool and "lost" the JVM's
> > garbage collector should take care of it.
> > PoolableObjectFactory.destroyObject won't get a chance to clean up
> > that object.
> >
> > If you want a way to clean up after an object instance is garbage
> > collected you should look into ReferenceQueue and taking clean up
> > action when an instance is no more.
> >
> > HTH.
> >
> > On 3/30/07, Conrad CRAMPTON PSE 52704
> > <co...@kent.pnn.police.uk> 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
>
>

Re: pool - cleaning up resources on JVM exit

Posted by Will Pugh <wi...@sourcelabs.com>.
Finalizers can be a pain, but might for this scenario they might work 
for you.

Sandy McArthur wrote:
> When the JVM crashes there is no cleaning up, the JVM just exits and
> the OS will clean up what it can. Pool cannot recover from a JVM
> crash.
>
> When the JVM exits there will be a bit more clean up. Whether or not
> it's a full clean up or something else will depend on your use of the
> shutdown handlers. Pool does not use shutdown handlers.
>
> If a borrowed object isn't returned to the pool and "lost" the JVM's
> garbage collector should take care of it.
> PoolableObjectFactory.destroyObject won't get a chance to clean up
> that object.
>
> If you want a way to clean up after an object instance is garbage
> collected you should look into ReferenceQueue and taking clean up
> action when an instance is no more.
>
> HTH.
>
> On 3/30/07, Conrad CRAMPTON PSE 52704
> <co...@kent.pnn.police.uk> 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


Re: pool - cleaning up resources on JVM exit

Posted by Sandy McArthur <sa...@apache.org>.
When the JVM crashes there is no cleaning up, the JVM just exits and
the OS will clean up what it can. Pool cannot recover from a JVM
crash.

When the JVM exits there will be a bit more clean up. Whether or not
it's a full clean up or something else will depend on your use of the
shutdown handlers. Pool does not use shutdown handlers.

If a borrowed object isn't returned to the pool and "lost" the JVM's
garbage collector should take care of it.
PoolableObjectFactory.destroyObject won't get a chance to clean up
that object.

If you want a way to clean up after an object instance is garbage
collected you should look into ReferenceQueue and taking clean up
action when an instance is no more.

HTH.

On 3/30/07, Conrad CRAMPTON PSE 52704
<co...@kent.pnn.police.uk> 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
>
>


-- 
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

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


Re: pool - cleaning up resources on JVM exit

Posted by Tom Muldoon <to...@firstbest.com>.
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