commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <p...@steitz.com>
Subject Re: [POOL] you can return your object several times?
Date Thu, 05 Jun 2008 01:16:19 GMT
kpetrov wrote:
> I tested a simple scenario where I return the same object several times:
> 		PoolableJmsTemplateFactory pjtf = new PoolableJmsTemplateFactory();
> 		pjtf.setConnectionFactory(connectionFactory);
> 		ObjectPool pool = new SoftReferenceObjectPool(pjtf);
> 		System.out.println("Idle templates:"+pool.getNumIdle());
> 		JmsTemplate jmsTemplate = (JmsTemplate)pool.borrowObject();
> 		System.out.println("Active templates:"+pool.getNumActive());
> 		JmsTemplate jmsTemplate2 = (JmsTemplate)pool.borrowObject();
> 		System.out.println("Active templates:"+pool.getNumActive());
> 		pool.returnObject(jmsTemplate);
> 		System.out.println("Active templates:"+pool.getNumActive());
> 		pool.returnObject(jmsTemplate2);
> 		System.out.println("Active templates:"+pool.getNumActive());
> 		System.out.println("Idle templates:"+pool.getNumIdle());
> 		pool.returnObject(jmsTemplate2);
> 		pool.returnObject(jmsTemplate2);
> 		System.out.println("Active templates:"+pool.getNumActive());
> 		System.out.println("Idle templates:"+pool.getNumIdle());
>
> What I get is a very unpleasant result:
>
> Idle templates:0
> Active templates:1
> Active templates:2
> Active templates:1
> Active templates:0
> Idle templates:2
> Active templates:-2
> Idle templates:4
>
> The pool let me return the object several times!
> Shouldn't it throw an exception or at least not have negative number of
> active objects?
>
> On top of that, when I tried to borrow objects again the same pool, the same
> object was returned several times. This is even worse than the negative
> number of active objects.
>
> Why is it implemented in such a way?
>   
Returning the same object twice in sequence violates the contract of the 
pool interface.  Validity of counters also depends on following the 
borrow-return contract.

Phil


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


Mime
View raw message