openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tuomas Hynninen" <tuomas.hynni...@surveypal.com>
Subject Multithreading problem
Date Wed, 28 Sep 2011 10:38:17 GMT
Hi!

I've been getting this error randomly:

<openjpa-2.1.0-r422266:1071316 fatal internal error> org.apache.openjpa.util.InternalException:
Multiple concurrent threads attempted to access a single broker. By default brokers are not
thread safe; if you require and/or intend a broker to be accessed by more than one thread,
set the openjpa.Multithreaded property to true to override the default behavior.
at org.apache.openjpa.kernel.BrokerImpl.endOperation(BrokerImpl.java:1935)
...

The pattern in my web app is the "entity manager per request" pattern, implemented like this:

http://www.uta.fi/~th77842/PersistenceRequestListener.java
http://www.uta.fi/~th77842/PersistenceManager.java

Basically, I force each request to have its own EntityManager. Some persisted entities are
shared between threads, but not EntityManagers.

The problem only occurs when it's a Tomcat specific thread (e.g. TP-Processor) using an EntityManager.
I haven't had the problem using my own agent threads or using the ThreadPoolExecutor 
to process jobs. The problem has happened on inserts, selects or accessing a field in a persisted
entity.

The servlet container I use is Tomcat 6. The database is PostgreSQL 8.1.4. JPA related libraries
I use: openjpa-2.1.0.jar, geronimo-jpa_2.0_spec-1.1.jar, geronimo-jta_1.1_spec-1.1.1.jar.

Persistence configuration:

<properties>
      <property name="openjpa.jdbc.DBDictionary" value="postgres"/>
      <property name="openjpa.jdbc.DriverDataSource" value="dbcp"/>
      <property name="openjpa.ConnectionProperties"
                value="DriverClassName=org.postgresql.Driver,
                  Url=jdbc:postgresql://...,
                  MaxActive=100,
                  MaxWait=10000,
                  Username=test,
                  Password=test"/>
      <property name="openjpa.ConnectionDriverName"
                value="org.apache.commons.dbcp.BasicDataSource"/>
      <property name="openjpa.Log" value="log4j"/>
      <property name="openjpa.ConnectionFactoryProperties"
    value="PrettyPrint=true, PrettyPrintLineLength=80, PrintParameters=true"/>
      <property name="openjpa.DataCache" value="false"/>
      <property name="openjpa.InitializeEagerly" value="true"/>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
</properties>

For the life of me I can't figure out why it's still happening. I am certain it's some subtle
(or not so subtle) bug in my code or in the configuration I've done. I can understand if OpenJPA
throws the error on 
persisted entities which are shared between threads, but it shouldn't happen on simple inserts.

Any help would be appreciated. Thanks!
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message