You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Tino Schöllhorn <t....@tiscali.de> on 2004/08/17 12:09:27 UTC
ConcurrentModification!!!
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Jin Bal <ji...@hotmail.com>.
Try not to modify the HashMap whilt iterating through it. perform the
operations on the iterator itself.
I had same prob with a list - i used iterator to find objects to remove then
removed them from the list rather than the iterator and had the same error
----- Original Message -----
From: "Tino Schöllhorn" <t....@tiscali.de>
To: <oj...@db.apache.org>
Sent: Tuesday, August 17, 2004 11:18 AM
Subject: Re: ConcurrentModification!!!
> 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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Armin Waibel <ar...@apache.org>.
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" <ar...@apache.org>
> To: "OJB Users List" <oj...@db.apache.org>
> 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: ojb-user-unsubscribe@db.apache.org
>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Fiona Magner <f_...@hotmail.com>.
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. When interacting with the
database then I simply create new transactions from this ODMG instance and
use those. Is this thread safe?
Thanks as always
Fiona
----- Original Message -----
From: "Armin Waibel" <ar...@apache.org>
To: "OJB Users List" <oj...@db.apache.org>
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: ojb-user-unsubscribe@db.apache.org
> >>> For additional commands, e-mail: ojb-user-help@db.apache.org
> >>>
> >>>
> >>>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Armin Waibel <ar...@apache.org>.
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(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: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Tino Schöllhorn <t....@tiscali.de>.
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: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Armin Waibel <ar...@apache.org>.
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: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: ConcurrentModification!!!
Posted by Tino Schöllhorn <t....@tiscali.de>.
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org