Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ejb Timer throwing javax.ejb.ConcurrentAccessTimeoutException: Unable to get write lock on

my application is running on tomee and I have the ejb timer to trigger the timeout method every two minutes. The timer triggered the timeout method first time and is still running when the timer tried to trigger the same method for second time. And it threw the following exception..

javax.ejb.ConcurrentAccessTimeoutException: Unable to get write lock on 'timeout' method for: com.abc.xyz
        at org.apache.openejb.core.singleton.SingletonContainer.aquireLock(SingletonContainer.java:298)
        at org.apache.openejb.core.singleton.SingletonContainer._invoke(SingletonContainer.java:217)
        at org.apache.openejb.core.singleton.SingletonContainer.invoke(SingletonContainer.java:197)
        at org.apache.openejb.core.timer.EjbTimerServiceImpl.ejbTimeout(EjbTimerServiceImpl.java:769)
        at org.apache.openejb.core.timer.EjbTimeoutJob.execute(EjbTimeoutJob.java:39)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:207)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)

All my log is filled up with the same stacktrace and it continues to occur until I stop the server..

Can we make the timerservice not to trigger the method if it is already running? or is there a way to timeout the first call before it is triggered again..

Thanks,

like image 570
Sampath Pasupunuri Avatar asked Dec 29 '25 16:12

Sampath Pasupunuri


1 Answers

Is your timed EJB a singleton bean? By default singletons use container managed concurrency with write locks that guarantee exclusive access for all methods.

The openejb.xml configures the AccessTimeout for a singleton EJB. After that timeout the exception you have seen will be thrown. Please see here as well: http://tomee.apache.org/singleton-beans.html

Solutions might be:

  1. Use a stateless session bean as the timer bean
  2. Define a read lock on the timer method
  3. Don't use a repeating timer but schedule the next execution of your timer at the end of the current execution.
like image 187
Robert Panzer Avatar answered Jan 01 '26 05:01

Robert Panzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!