Hi Sylvain,

[EMAIL PROTECTED] wrote:
Hello,
I'm using OJB in my web application and I have some problem with PB instances creation.
Each time I want to read/write data from/to my database I create a PB intance:
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
The problem is that lot of PB instances are created and never destroyed.
I can see that in logs: "Already created persistence broker instances: x".
For that I close the broker instance each time:
broker.close();
But I have noticed that this function doesn't destroy the PB instance.
So what is the job of this function?

broker instances are not destroyed, because it's expensive to create them. Thus OJB is pooling broker instances.
broker.close() simply makes the instances unavailable for further calls and puts the instance back to the pool.


How to destroy PB instance and prevent that the number of PB instances is equal to the maximum?

If you close broker instancecs always after usage the number of active broker instances (i.e. brokers that are borrowed from the pool) equals the number servlet instances requesting a broker.


You can change the broker pool behaviour through settings in OJB.properties:

# specifies the behaviour of the pool when broker capacity is
# exhausted (see maxActive above)
# 0 - fail
# 1 - block
# 2 - grow
whenExhaustedAction=0

The default setting is 0, so the pool throws an exception if an instance is requested when the pool is exhausted.
By setting this value to 2 the pool would simply grow and a new broker instance.
By setting it to 1 you can avoid growing of the pool, the application is blockes until an instance is available from the pool.


cheers,
Thomas


Thanks for any help
Sylvain


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to