Our application is a Swing application that displays data fetched directly
from the database. There is a single entity manager and an extended
persistence context. Because we want the GUI to be responsive, all the
transactional database operations are executed into a single separate worker
thread. We don't use the openjpa.Multithreaded = true option because it
introduces overhead and also because it is susceptible to a deadlock (issue 
OPENJPA-1716).
Calling a getter on one entity inside the Event Dispatch Thread, while other
operations are executed onto the entity manager in the separate worker
thread, will automatically access the BrokerImpl concurrently from the EDT
too. Here is a snippet of a stacktrace confirming this:

Exception in thread "AWT-EventQueue-0" <openjpa-1.2.1-r752877:753278 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:1792) 
at org.apache.openjpa.kernel.BrokerImpl.isActive(BrokerImpl.java:1740) 
at
org.apache.openjpa.kernel.StateManagerImpl.beforeRead(StateManagerImpl.java:942)
 
at
org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1477)
 
at
org.apache.openjpa.enhance.RedefinitionHelper.accessingField(RedefinitionHelper.java:59)
 
at org.apache.openjpa.enhance.Tabelle$Pratica$pcsubclass.getClienti(Unknown
Source) 
at Modelli.ClienteView.<init>(ClienteView.java:93) 
at Modelli.ClienteController.<init>(ClienteController.java:39) 
at Modelli.PraticaController.createPraticaView(PraticaController.java:51)

My question would be: is there proper way to prevent this from happening?
How can I keep executing the time-consuming transactional operations into a
worker thread, and still be able to call a getter onto another entity, in a
thread different than the worker thread, without causing this exception?
-- 
View this message in context: 
http://openjpa.208410.n2.nabble.com/Calling-a-getter-of-an-entity-will-access-the-broker-tp5325919p5325919.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to