Hi,

> 
> Hello,
> 
> OK! It is a bit clearer for me, thanks.
> Each time I want to use a broker I should do:
> 
> broker = PersistenceBrokerFactory.defaultPersistenceBroker();
> //I use the broker
> broker.close();


Yes, this is the way it should be done.
 
> Is it better to do this EACH time I use the broker or ask for 
> a broker one time (when the application start) and close 
> after (all) the use?

It is better to do it each time. 

If this is an "issue" for you, I suggest you look at using ODMG; it hides
all broker usage from your application.


> About the MAX number of broker in OJB.properties, is it a 
> good way to set this number to 100 or even 1000?
> 
> Finally what is the exact meaning of this 2 log messages:
> "Already created persistence broker instances: x"?
> "Already created connections: 3 returning: ..."?


I'm afraid I don't know precisely.. 

Cheers,

Charles.
 
> Thanks for your help
> Sylvain
> 
> 
> 
> 
> -----Message d'origine-----
> De: Charles Anthony [mailto:[EMAIL PROTECTED]
> Date: lundi, 27. octobre 2003 11:27
> À: 'OJB Users List'
> Objet: RE: problem with PB instances creation
> 
> 
> Hi,
> 
> at line 27, you should repeat lines 9-13.
> 
> At line 10 
> PersistenceBrokerFactory.defaultPersistenceBroker() asks the pool
> for a broker, creating one *if* *necessary*. 
> broker.close releases some resources from the broker, and  returns the
> broker to the pool.
> 
> In other words, after you close the broker, you can no longer 
> use it. You
> must get another broker.
> 
> If you really need to know how many (active) brokers there 
> are in the pool,
> you should be able to do
> 
> PersistenceBrokerFactoryDefaultImpl factory =
> (PersistenceBrokerFactoryDefaultImpl)
> PersistenceBrokerFactoryFactory.instance();
> int brokersInPool = factory.activePersistenceBroker();
> 
> Cheers,
> 
> Charles
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> > Sent: 27 October 2003 10:17
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Subject: RE: problem with PB instances creation
> > 
> > 
> > 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]
> > 
> > 
> 
> 
> This email and any attachments are strictly confidential and 
> are intended
> solely for the addressee. If you are not the intended 
> recipient you must
> not disclose, forward, copy or take any action in reliance on 
> this message
> or its attachments. If you have received this email in error 
> please notify
> the sender as soon as possible and delete it from your 
> computer systems.
> Any views or opinions presented are solely those of the 
> author and do not
> necessarily reflect those of HPD Software Limited or its affiliates.
> 
>  At present the integrity of email across the internet cannot 
> be guaranteed
> and messages sent via this medium are potentially at risk.  
> All liability
> is excluded to the extent permitted by law for any claims 
> arising as a re-
> sult of the use of this medium to transmit information by or to 
> HPD Software Limited or its affiliates.
> 
> 
> 
> ---------------------------------------------------------------------
> 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]
> 
> 


This email and any attachments are strictly confidential and are intended
solely for the addressee. If you are not the intended recipient you must
not disclose, forward, copy or take any action in reliance on this message
or its attachments. If you have received this email in error please notify
the sender as soon as possible and delete it from your computer systems.
Any views or opinions presented are solely those of the author and do not
necessarily reflect those of HPD Software Limited or its affiliates.

 At present the integrity of email across the internet cannot be guaranteed
and messages sent via this medium are potentially at risk.  All liability
is excluded to the extent permitted by law for any claims arising as a re-
sult of the use of this medium to transmit information by or to 
HPD Software Limited or its affiliates.



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

Reply via email to