Hello Thomas,

Is there a way to check how many instances are contained in the pool?

You can find an example below.
You create a broker instance in line 10, right?
You use the broker instance first time in line 19. After this use you close() the 
instance.
But the problem is if you do the close() in line 25 when you use the broker for the 
second time in line 29 you have a ConnectionNotInProgressException.

Do I have to create a second broker?
Or do I have to call a broker from the pool? How?

Thanks for your help
Sylvain


1 public class MyExample {
2
3 private PersistenceBroker broker;
4
5 public void test() {
6       /**
7       * Persistence Broker
8       */
9       try {
10              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
11      } catch (Throwable t) {
12              t.printStackTrace();
13      }
14
15      Criteria crit = new Criteria();
16      ...
17
18      try {
19              broker.beginTransaction();
20              //query 1...
21              broker.commitTransaction();
22      } catch (Throwable t) {
23              broker.abortTransaction();
24      } finally {
25              broker.close();
26      }
27
28      try {
29              broker.beginTransaction();
30              //query 2...
31              broker.commitTransaction();
32      } catch (Throwable t) {
33              broker.abortTransaction();
34      } finally {
35              broker.close();
36      }
37  }
38 }

        
-----Message d'origine-----
De: Thomas Mahler [mailto:[EMAIL PROTECTED]
Date: vendredi, 24. octobre 2003 18:17
À: OJB Users List
Objet: Re: problem with PB instances creation


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]


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

Reply via email to