[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
IllegalMonitorStateException but everything seems synchronized  XML
Forum Index -> Terracotta Platform
Author Message
horkhe

journeyman

Joined: 11/01/2008 11:24:46
Messages: 10
Location: Nizhniy Novgorod, Russia
Offline

Hi Folks,

I am developing a simulator of sensor node networks and would like to use Terracotta to boost its performance. In the application I have the Simulator class which starts a worker thread to actually perform simulation of an assigned network nodes. And the Coordinator class which distributes work among simulators and ensures synchronization. I designed so that every application instance spawns as many simulators as there CPUs available.

The application works perfectly well when running without Terracotta. But when I start it under Terracotta it throws IllegalMonitorStateException immediately. Which is weird since I have everything synchronized and configured overkilling locking stanza

Code:
 <locks>
     <autolock auto-synchronized="false">
         <lock-level>write</lock-level>
         <method-expression>* *..*.*(..)</method-expression>
     </autolock>
 </locks>
 


Could you please advise where I might be wrong? Thank you in advance.

P.S. Here is the detailed exception text:
Code:
 java.lang.IllegalMonitorStateException: 
 *******************************************************************************
 An IllegalStateMonitor is usually caused by one of the following:
 1) No synchronization
 2) The object synchronized is not the same as the object waited/notified
 3) The object being waited/notified on is a Terracotta distributed object, but no Terracotta auto-lock has been specified.
 
 For more information on this issue, please visit our Troubleshooting Guide at:
 http://terracotta.org/kit/troubleshooting
 *******************************************************************************
 
 	at com.tc.object.tx.ClientTransactionManagerImpl.wait(ClientTransactionManagerImpl.java:218)
 	at com.tc.object.bytecode.ManagerImpl.objectWait0(ManagerImpl.java:410)
 	at com.tc.object.bytecode.ManagerUtil.objectWait0(ManagerUtil.java:427)
 	at com.synapsense.avrorati.sync.Simulator.__tc_wrapped_workerThreadLogic(Simulator.java:151)
 	at com.synapsense.avrorati.sync.Simulator.workerThreadLogic(Simulator.java)
 	at com.synapsense.avrorati.sync.Simulator.access$0(Simulator.java:147)
 	at com.synapsense.avrorati.sync.Simulator$1.run(Simulator.java:65)
 	at java.lang.Thread.run(Thread.java:619)
  INFO [Thread-15] Simulator - Worker thread started
 com.tc.object.tx.UnlockedSharedObjectException: 
 *******************************************************************************
 Attempt to access a shared object outside the scope of a shared lock.  
 All access to shared objects must be within the scope of one or more shared locks defined in your Terracotta configuration.  
 Please alter the locks section of your Terracotta configuration so that this access is auto-locked or protected by a named lock.
 
 For more information on this issue, please visit our Troubleshooting Guide at:
  http://terracotta.org/kit/troubleshooting
 
 
     Caused by Thread: Thread-14  in  VM(0)
     Shared Object Type: com.synapsense.avrorati.sync.Simulator
 *******************************************************************************
 
 	at com.tc.object.tx.ClientTransactionManagerImpl.getTransaction(ClientTransactionManagerImpl.java:303)
 	at com.tc.object.tx.ClientTransactionManagerImpl.fieldChanged(ClientTransactionManagerImpl.java:598)
 	at com.tc.object.TCObjectImpl.objectFieldChanged(TCObjectImpl.java:305)
 	at com.tc.object.TCObjectImpl.booleanFieldChanged(TCObjectImpl.java:325)
 	at com.synapsense.avrorati.sync.Simulator.__tc_setisNotConfigured_(Simulator.java)
 	at com.synapsense.avrorati.sync.Simulator.__tc_wrapped_workerThreadLogic(Simulator.java:182)
 	at com.synapsense.avrorati.sync.Simulator.workerThreadLogic(Simulator.java)
 	at com.synapsense.avrorati.sync.Simulator.access$0(Simulator.java:147)
 	at com.synapsense.avrorati.sync.Simulator$1.run(Simulator.java:65)
 	at java.lang.Thread.run(Thread.java:619)
 com.tc.object.tx.UnlockedSharedObjectException: 
 *******************************************************************************
 Attempt to access a shared object outside the scope of a shared lock.  
 All access to shared objects must be within the scope of one or more shared locks defined in your Terracotta configuration.  
 Please alter the locks section of your Terracotta configuration so that this access is auto-locked or protected by a named lock.
 
 For more information on this issue, please visit our Troubleshooting Guide at:
  http://terracotta.org/kit/troubleshooting
 
 
     Caused by Thread: Thread-14  in  VM(0)
     
 *******************************************************************************
 
 	at com.tc.object.tx.ClientTransactionManagerImpl.getTransaction(ClientTransactionManagerImpl.java:303)
 	at com.tc.object.tx.ClientTransactionManagerImpl.getTransaction(ClientTransactionManagerImpl.java:286)
 	at com.tc.object.tx.ClientTransactionManagerImpl.commit(ClientTransactionManagerImpl.java:355)
 	at com.tc.object.bytecode.ManagerImpl.monitorExit(ManagerImpl.java:520)
 	at com.tc.object.bytecode.ManagerUtil.monitorExit(ManagerUtil.java:478)
 	at com.synapsense.avrorati.sync.Simulator.workerThreadLogic(Simulator.java)
 	at com.synapsense.avrorati.sync.Simulator.access$0(Simulator.java:147)
 	at com.synapsense.avrorati.sync.Simulator$1.run(Simulator.java:65)
 	at java.lang.Thread.run(Thread.java:619)
 Exception in thread "Thread-14" com.tc.object.tx.UnlockedSharedObjectException: 
 *******************************************************************************
 Attempt to access a shared object outside the scope of a shared lock.  
 All access to shared objects must be within the scope of one or more shared locks defined in your Terracotta configuration.  
 Please alter the locks section of your Terracotta configuration so that this access is auto-locked or protected by a named lock.
 
 For more information on this issue, please visit our Troubleshooting Guide at:
  http://terracotta.org/kit/troubleshooting
 
 
     Caused by Thread: Thread-14  in  VM(0)
     
 *******************************************************************************
 
 	at com.tc.object.tx.ClientTransactionManagerImpl.getTransaction(ClientTransactionManagerImpl.java:303)
 	at com.tc.object.tx.ClientTransactionManagerImpl.getTransaction(ClientTransactionManagerImpl.java:286)
 	at com.tc.object.tx.ClientTransactionManagerImpl.commit(ClientTransactionManagerImpl.java:355)
 	at com.tc.object.bytecode.ManagerImpl.monitorExit(ManagerImpl.java:520)
 	at com.tc.object.bytecode.ManagerUtil.monitorExit(ManagerUtil.java:478)
 	at com.synapsense.avrorati.sync.Simulator.workerThreadLogic(Simulator.java)
 	at com.synapsense.avrorati.sync.Simulator.access$0(Simulator.java:147)
 	at com.synapsense.avrorati.sync.Simulator$1.run(Simulator.java:65)
 	at java.lang.Thread.run(Thread.java:619)
 
 Filename Simulator.java [Disk] Download
 Description
 Filesize 6 Kbytes
 Downloaded:  121 time(s)

 Filename tc-config.xml [Disk] Download
 Description
 Filesize 1 Kbytes
 Downloaded:  110 time(s)

 Filename Coordinator.java [Disk] Download
 Description
 Filesize 6 Kbytes
 Downloaded:  107 time(s)


Maxim Vladimirsky (Software Designer)
[WWW]
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Make sure you've read through this section thoroughly:

http://www.terracotta.org/web/display/docs/Concept+and+Architecture+Guide#ConceptandArchitectureGuide-Locks

[WWW]
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Also make sure it's not a lock-then-share gotcha:

http://www.terracotta.org/web/display/docs/Gotchas#Gotchas-LockThenShare

[WWW]
horkhe

journeyman

Joined: 11/01/2008 11:24:46
Messages: 10
Location: Nizhniy Novgorod, Russia
Offline

Thanks a lot, Taylor,

I made a lock-then-share mistake. The Simulator class started a thread in a constructor which called a Simulator synchronized method. So it grabbed the Simulator's lock before the Coordinator class had a chance to share the created simulator instance. When I fixed that, the problem went away.

Now I have another problem. It seems that the Simulator worker thread does not want to wake up from wait when notified by the Coordinator. I have not yet done decent investigation of this issue. So I will not bother you with it right away... may be after a day or two of struggle

Besides, after reading the first article you specified, I am thinking about refactoring the application to use ReentrantReadWriteLock. I like that it requires no any explicit configuration of Terracotta. Would you recommend to go for it?

Maxim Vladimirsky
Mera Networks

Maxim Vladimirsky (Software Designer)
[WWW]
horkhe

journeyman

Joined: 11/01/2008 11:24:46
Messages: 10
Location: Nizhniy Novgorod, Russia
Offline

I figured out that problem with the notification method has nothing to do with Terracotta. It is fixed now. And my application finally running under Terracotta. But it is much much slower than running on a pure JVM. E.g. a test which takes 30 seconds on a pure JVM lasts for 900 seconds under Terracotta. Probably my locking strategy does not fit very well the Terracotta architecture. I will try to use the Terracotta Admin Console to investigate that issue.

Kind regards
Maxim Vladimirky
Mera Networks

Maxim Vladimirsky (Software Designer)
[WWW]
 
Forum Index -> Terracotta Platform
Go to:   
Powered by JForum 2.1.7 © JForum Team