[concurrency-interest] Re: PooledLinkedBlockingQueue

Gregg Wonderly gregg.wonderly@pobox.com
Tue, 02 Nov 2004 08:52:26 -0600


Larry Riedel wrote:
> I think it is particularly lame to have to create/destroy an
> object for every time the pooled object is put/taken, when a
> mechanism for avoiding that (WeakReference/ReferenceQueue) is
> already in the JVM and just lacks a ReRegisterForFinalize()
> (CLR) style method.  But I would not object to the idea of
> having a pool specific object for each pooled object, one which
> has the same lifetime as the pooled object, but has (for
> example) a finalizer so the pooled object does not have to.

I guess I am not sure what you are saying here.  I am thinking that
I would create something like:

public class PublicInterfaceObject {
	PooledObjectPool pool = ...;
	public static PooledObject getInstance(...) {
		PooledObject obj = pool.getInstance(...);
		return new PublicPooledObject(pool, obj);
	}
}

public class PublicPooledObject {
	PooledObject delegate;
	PublicPooledObject( PooledObjectPool pool, PooledObject del ) {
		delegate = del;
	}

	private final void finalize() {
		pool.add(delegate);
	}

	... delegated methods if Proxy not used ...
}

It might be possible to incorporate a Proxy here, instead of a concrete 
class that delegates all methods...

Gregg