-
1. Re: How to notify client of CMT TX Timeout
nickarls Feb 5, 2013 4:29 AM (in response to markus78)Hmm. Haven't tested but at which point does an AFTER_FAILURE transactional CDI event fire? Or can you just use a normal interceptor and try digging out the underlying cause?
-
2. Re: How to notify client of CMT TX Timeout
markus78 Feb 5, 2013 9:44 AM (in response to nickarls)CDI Events would have been a nice solution, but I can't quite get it to work
15:20:30,560 INFO [stdout] (http-localhost/127.0.0.1:8080-1) Waiting for timeout 20 sec
15:20:40,552 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff82ef5225:-5dbeb42b:51111419:15 in state RUN
15:20:40,555 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff82ef5225:-5dbeb42b:51111419:15 invoked while multiple threads active within it.
15:20:40,556 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff82ef5225:-5dbeb42b:51111419:15 aborting with 1 threads active!
15:20:40,559 ERROR [org.jboss.weld.Event] (Transaction Reaper Worker 0) WELD-000401 Failure while notifying an observer of event com.my.ejb.HelloEvent@e6e445d
Very simple code...
package com.my.ejb; import javax.ejb.Stateless; import javax.enterprise.event.Observes; import javax.enterprise.event.TransactionPhase; @Stateless public class HelloListener { public void listenToHello(@Observes HelloEvent helloEvent) { System.out.println("Test: " + helloEvent); } public void listenToTxFail(@Observes(during=TransactionPhase.AFTER_FAILURE) HelloEvent helloEvent) { System.out.println("TX FAILED: " + helloEvent); } }
@Named("messenger") @Stateless public class HelloMessenger { @Inject private Event<com.my.ejb.HelloEvent> myEvent; public void test() { myEvent.fire(new HelloEvent("from bean " + System.currentTimeMillis())); System.out.println("Waiting for timeout 20 sec"); try{ Thread.sleep((1000*10)*2); }catch(Exception e){ e.printStackTrace(); } System.out.println("..."); } }
-
3. Re: How to notify client of CMT TX Timeout
nickarls Feb 5, 2013 12:52 PM (in response to markus78)For every problem there is a solution that is simple, elegant and doesn't work ;-)
-
4. Re: How to notify client of CMT TX Timeout
jbertram Feb 5, 2013 1:00 PM (in response to markus78)Is your goal simply to have the client timeout the call to the server after a certain time, ideally corresponding with the timeout of the transaction on the server?
-
5. Re: How to notify client of CMT TX Timeout
markus78 Feb 5, 2013 1:06 PM (in response to jbertram)Yes that is basically the functionality that I need.
-
6. Re: How to notify client of CMT TX Timeout
jbertram Feb 5, 2013 2:18 PM (in response to markus78)The first road-block here is that when the transaction times out the associated thread is not interrupted. This means that the thread will happily keep running long after the transaction is actually dead (which could potentially be quite awhile). Only when it tries to perform more work with the transaction (e.g. enlist another resource, commit, rollback, etc.) will an exception actually occur (as per spec). At this point the application itself can catch the exception and inform the client as necessary.
If you really want the client to abort its call after a certain amount of time then you'd have to execute the call in a special way to facilitate that behavior (e.g. using java.util.concurrent).
-
7. Re: How to notify client of CMT TX Timeout
markus78 Feb 5, 2013 2:58 PM (in response to jbertram)Yea thanks, It occured to me that perhaps all we really need is to set <set-tx-query-timeout> to true on our datasource, I will test that out first of all. Thanks for the help!
-
8. Re: How to notify client of CMT TX Timeout
jbertram Feb 5, 2013 3:02 PM (in response to markus78)1 of 1 people found this helpfulIf you are working with a JDBC datasource then <set-tx-query-timeout> will almost certainly help you (granted your JDBC driver obeys the query timeout).
-
9. Re: How to notify client of CMT TX Timeout
markus78 Feb 7, 2013 4:35 AM (in response to jbertram)The property setting worked like a charm, our DB driver now throws an exception when the TX timeout occurs! thanks.
-
10. Re: How to notify client of CMT TX Timeout
markus78 Jun 17, 2013 2:08 AM (in response to jbertram)Well , this worked for a while, but now we are getting problems with OOMEM unable to create new native thread, and a quick look in visualvm shows that the culprit is thousands of "Timer-" threads, created by our db2jcc driver..
/Markus