To be really careful about closing the broker, you may want to include a try/finally structure. Here is Charles' code modified:
public void onEvent() { PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker(); try { pb.store(this); // or whatever it is you want to do with the broker } finally { pb.close(); } } Charles Anthony [EMAIL PROTECTED] wrote: > Hi, > > You need to ensure that you are closing the broker. > > public void onEvent(){ > PersistenceBroker pb = > PersistenceBrokerFactory.defaultPersistenceBroker(); > pb.store(this); // or whatever it is you want to do with the broker > pb.close(); > } > > > You should only get brokers when you need them, and close them when you've > finished with them. > > HTH, > > Charles. > > > -----Original Message----- > > From: Michael Watson [mailto:[EMAIL PROTECTED] > > Sent: 09 October 2003 12:53 > > To: OJB Users List; [EMAIL PROTECTED] > > Subject: Re: ConcurrentModificationException > > > > > > Hi Armin, > > I have an object with an init method where I assign a > > PersistenceBroker > > instance using > > > > PersistenceBrokerFactory.defaultPersistenceBroker() > > > > This object then has an onEvent() method that is called and uses > > broker.store(). > > > > I tried modifying the object so that the broker is obtained > > in the onEvent > > instead of the init and I started getting > > "Borrow broker from pool failed" Exceptions. I have my > > connection-pool set > > up as follows: > > > > <connection-pool maxActive="-1" whenExhaustedAction="2" > > validationQuery="select 1 from t_client"/> > > > > Do you have any suggestions for what I might be doing wrong? > > > > Mike > > > > ----- Original Message ----- > > From: "Armin Waibel" <[EMAIL PROTECTED]> > > To: "OJB Users List" <[EMAIL PROTECTED]> > > Sent: Wednesday, October 08, 2003 6:02 PM > > Subject: Re: ConcurrentModificationException > > > > > > > Hi Michael, > > > > > > On Wed, 8 Oct 2003 17:31:15 +0100, Michael Watson > > > <[EMAIL PROTECTED]> wrote: > > > > > > > Hi all, > > > > > > > > I'm finding I quite reguarly get this exception when I'm > > attempting to > > > > call > > > > PersistenceBroker.store(Object) from multiple threads > > simultaneously. > > > > > > > Do several threads share the same PB instance? > > > If so, this is not allowed. PB instances are not > > > threadsafe itself, but they are pooled so it's no > > > performance impact to use a separate PB instance for each thread. > > > > > > regards, > > > Armin > > > > > > > <?xml version='1.0'?> > > > > <exception> > > > > <cause> > > > > <detailMessage/> > > > > > > <exceptionClass>java.util.ConcurrentModificationException</exc > > eptionClass> > > > > <stackTrace> > > > > > > <stackTrace>java.util.AbstractList$Itr.checkForComodification( > > AbstractList.j > > > > ava:444)</stackTrace> > > > > > > <stackTrace>java.util.AbstractList$Itr.next(AbstractList.java: > > 417)</stackTra > > > > ce> > > > > > > <stackTrace>java.util.AbstractCollection.remove(AbstractCollec > > tion.java:250) > > > > </stackTrace> > > > > > > <stackTrace>org.apache.ojb.broker.core.PersistenceBrokerImpl.s > > tore(Unknown > > > > Source)</stackTrace> > > > > > > <stackTrace>org.apache.ojb.broker.core.PersistenceBrokerImpl.s > > tore(Unknown > > > > Source)</stackTrace> > > > > > > <stackTrace>org.apache.ojb.broker.core.DelegatingPersistenceBr > > oker.store(Unk > > > > nown Source)</stackTrace> > > > > ... > > > > </stackTrace> > > > > </cause> > > > > <detailMessage>Failed to update History record > > > > java.util.ConcurrentModificationException</detailMessage> > > > > > > <exceptionClass>org.apache.ojb.broker.PersistenceBrokerExcepti > > on</exceptionC > > > > lass> > > > > <stackTrace/> > > > > </exception> > > > > > > > > Obviously somewhere in the broker there's been an attempt > > to modify the > > > > structure of a list by 2 or more threads simultaneously. > > > > > > > > My question is, has anything been done to prevent this in a newer > > > > version or > > > > should I just catch these exceptions and retry the store? > > > > > > > > I'm using ojb-1.0.rc3 at the moment. > > > > > > > > Regards, > > > > > > > > Mike > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > 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] > > > > > > > > > > > > --------------------------------------------------------------------- > > 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]