[OJB-developers] nasty bug in SequenceManagerFactory
Brought to you by:
thma
From: Georg S. <ge...@me...> - 2002-04-19 13:13:52
|
Hi Thomas, I think I found a nasty bug related to the SequenceManager which shows up in multithreaded environments: In the constructor of PersistenceBrokerImpl a SequenceManager is obtained by the following line: m_SequenceManager = SequenceManagerFactory.getSequenceManager(this); If this is the first time, SequenceManagerFactory will instantiate a new SequenceManger and give it the this-pointer. Subsequent calls to getSequenceManager will return the same SequenceManager instance. The problem is that once the PersistenceBrokerImpl is finished with its tasks it will get returned to the Broker-Pool and is now available for another thread, but it also forms part of the SequenceManager which will get returned from the factory for new PersistenceBrokerImpl instances. The result is that > 2 threads are accessing the same connection and wrecking havoc on it. My short-term solution is to create a PersistenceBroker at the beginning of the program which I never use again. The real solution would be to create a new PersistenceBroker in the SequenceManagerFactory the first time it is being called. Unfortunately each call to create a new PersistenceBroker calls the SequenceManagerFactory itself again and we are getting into a nice circle (Stack Overflow). I suppose there should be a constructor in PersistenceBrokerImpl that doesn't create a SequenceManager. Regards Georg |