Fiona Magner wrote:
Hi,

Would this also be an issue with ODMG? I am using ODMG in a web application
and have just one shared instance of my ODMG implementation (ie
OJB.getInstance()) in the application scope.

That's the recommended way to use it.

When interacting with the
database then I simply create new transactions from this ODMG instance and
use those. Is this thread safe?


yep, the ODMG-api should be thread-safe. If you have a concurrent access issue, please post a test case or some (pseudo) code to reproduce the problem.


regards,
Armin

Thanks as always
Fiona

----- Original Message ----- From: "Armin Waibel" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, August 17, 2004 12:42 PM
Subject: Re: ConcurrentModification!!!




Tino Sch�llhorn wrote:


Hi Armin,

how do I make sure that different threads get different connections?

Each PB instance use its own connection, so if you use a PB instance per thread, OJB automatic use its own connection instance per PB instance.


I
get my PB instances form a helper method:

public static PersistenceBroker getPBFromAlias(String jcdAlias) {

===>????

   MetadataManager mm = MetadataManager.getInstance();
   ConnectionRepository cr = mm.connectionRepository();

   PBKey pbKey = cr.getStandardPBKeyForJcdAlias(jcdAlias);

   if (pbKey == null) {
       throw new RuntimeException(
           "Konnte keinen PersistenceBroker zu alias '" + jcdAlias + "'
finden!"
       );
   }

===>????

Why not simply:

PBKey pbKey = new PBKey(jcdAlias);
PersistenceBroker res =
PersistenceBrokerFactory.createPersistenceBroker(pbKey);

or

PersistenceBroker res =
PersistenceBrokerFactory.createPersistenceBroker(jcdAlias, null, null);


   return res;
}


regards, Armin



I am invoking this method in different threads? Do I have to synchronize
this method?

Tino

Armin Waibel wrote:


Hi Tino,

are you sure that the used PB instance was not shared across different
threads? The PB itself is not threadsafe, each thread has to use its
own instance of PB obtained from the PBF.

>> java.util.ConcurrentModificationException
>>     at java.util.HashMap$HashIterator.nextEntry(HashMap.java:782)
>>     at java.util.HashMap$KeyIterator.next(HashMap.java:818)
>>     at
>> org.apache.ojb.broker.cache.InternalCache.pushToRealCache(Unknown
Source)


<snip> private void pushToRealCache() { Iterator it = localCache.keySet().iterator(); Identity oid; while (it.hasNext()) { oid = (Identity) it.next(); realCache.cache(oid, localCache.get(oid)); } localCache.clear(); } </snip>

You can see from the code snip that a ConcurrentModificationException
can occur when different threads using the same PB instance (each PB
has an own instance of InternalCache).

regards,
Armin


Tino Sch�llhorn wrote:


I forgot to mention that we are using OJB 1.0 !

Tino Sch�llhorn wrote:


Hi,

we are using OJB in a Tomcat-Application and are greatly satisfied.
Now we are moving our application to a windows 2003 server with 2
processors and we encounter some problems. One is the following:

We implemented a DownloadServlet which is responsible for delivering
Streams of previously uploaded files. But on this machine we get
errors when downloading some files (the thing is: sometimes it is
ok, sometimes it is not). Here is the Stacktrace which I think could
be responsible to this problem:

java.util.ConcurrentModificationException
   at java.util.HashMap$HashIterator.nextEntry(HashMap.java:782)
   at java.util.HashMap$KeyIterator.next(HashMap.java:818)
   at
org.apache.ojb.broker.cache.InternalCache.pushToRealCache(Unknown
Source)
   at


org.apache.ojb.broker.cache.InternalCache.disableMaterializationCache(Unknow n

Source)
   at


org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown

Source)
   at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown
Source)
   at


org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByQuery(Unknown

Source)
   at


org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Unkn own

Source)
   at


org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Unkn own

Source)
   at kos.generator.DataObject.getObjectById(DataObject.java:368)
   at kos.wnetz.om.base.File.getFileById(File.java:156)
   at
kos.wnetz.modules.fs2.DownloadServlet.doGet(DownloadServlet.java:34)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Do you have any ideas how this error could be prevented? Is this a synchronization-problem of OJB? I will try to synchonize our DownloadServlet - but due to performance-reasons this is not our preferred solution (;-))

With regards
Tino





--------------------------------------------------------------------- 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]




---------------------------------------------------------------------
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