There is a close method that does the cleanup but you have to call it directly.
You can of course subclass but using a finalizer is not recommended. Using a close method and making sure all your object are closed is much better.
Relying on the GC to call your finalize method is not very good. It can take a long time before your network connection is closed and remember the GC is run when there is a low memory condition so it is very dangerous to create object inside a finalizer (iterators, messages to be send to the reciever, ...).
and of course you have to take threading / deadlocks into account... very dangerous/difficult/untestable code
You will be better off designing something without finalizers.
Take a look DBCP, PoolableConnection for a nice design pattern for using pools.
Regards Dirk
Sy Andrew wrote:
When an instance of GenericObjectPool is about to be garbage collected, does
it release the objects/resources in its pool (e.g. by calling the
PoolableObjectFactory.destroyObject(Object) method)? I plan to use
GenericObjectPool to pool some objects, where each of these objects is
holding on to a network connection. Ideally, the connections should always
be closed cleanly.
Of course I can also implement finalize() on my own objects, or use a
PhantomReference to the GenericObjectPool instance to ensure that this
happens. But I just wanted to make sure first that GenericObjectPool is not
already doing the work for me. I looked at the source code for
GenericObjectPool and it did not seem to be doing this functionality. But
since it's my first time looking at the code, can anyone confirm this?
Thanks.
-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions USA, Inc. and are intended only for the addressee(s). The information contained herein may include trade secrets or privileged or otherwise confidential information. Unauthorized review, forwarding, printing, copying, distributing, or using such information is strictly prohibited and may be unlawful. If you received this message in error, or have reason to believe you are not authorized to receive it, please promptly delete this message and notify the sender by e-mail with a copy to [EMAIL PROTECTED] Thank you
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
