Hi Armin,
how do I make sure that different threads get different connections? 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!"
);
}
PersistenceBroker res = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
return res;
}
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(Unknown 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(Unknown Source)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Unknown 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]
