10 Replies Latest reply on Jun 17, 2013 2:08 AM by markus78

    How to notify client of CMT TX Timeout

    markus78 Newbie

      Hi,

       

      Our previous application server (IBM Websphere.. *shruggs*) it had some pretty handy ejb spec violations, whenever we would get a CMT TX timeout an exception was raised letting the client know that the TX timedout.

      JBoss7 does not do this, and after reading the ejb3.1 specification I'm pretty sure JBoss7 follows the spec to the letter so there should not be any exception due to TX timeout.

       

      What techniques are available to notify the client that the TX timed out? Do we have to implement asyncronous calls from the client and add timeout checks on the client?

       

      Any ideas are welcome.

       

      /Markus

        • 1. Re: How to notify client of CMT TX Timeout
          Nicklas Karlsson Master

          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 Newbie

            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
              Nicklas Karlsson Master

              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
                Justin Bertram Master

                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 Newbie

                  Yes that is basically the functionality that I need.

                  • 6. Re: How to notify client of CMT TX Timeout
                    Justin Bertram Master

                    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 Newbie

                      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
                        Justin Bertram Master

                        If 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). 

                        1 of 1 people found this helpful
                        • 9. Re: How to notify client of CMT TX Timeout
                          markus78 Newbie

                          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 Newbie

                            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