4 Replies Latest reply on Feb 15, 2012 8:49 PM by csariedd

    Method Timeout JBoss EAP 5.1

    csariedd

      Hi,

       

      I was wondering if there's a way to monitor the execution time of a method and stop it on a timeout

      I have attempted to annotate a webservice method with @TransactionTimeout(1)

       

      First I am not able to find the org.jboss.tm.TransactionManagerService;

      Second I understand the values are in second, I'm interested in millisecond values.

       

      Thanks

        • 1. Re: Method Timeout JBoss EAP 5.1
          wdfink

          I'm not very familiar with webservices, but

          the transaction manager is only to ensure that the transaction timed out and can not commited after that.

           

          The running method and webservice will not be interrupted!

          • 2. Re: Method Timeout JBoss EAP 5.1
            csariedd

            Thanks for the reply. It seems that transaction time out is not what I'm looking for.

             

            Does JBoss have the watchdog timeou mechanism somewhere?

            What I'm trying to achieve is for the webservice operation to timeout internally by killing a thread that attempts to access an internal resource.

            Otherwise I'll have to do it myself.

            • 3. Re: Method Timeout JBoss EAP 5.1
              wdfink

              As the JEE spec is, you don't have to controll threads! Never start or stop threads or interfering in handling of it. Also you must not use any java.*io*.

               

              What you might do is to use a asynchronous approach and wait for the future object some time, here you can cancel the operation. But it is the responsibillity of the container how to handle it, it might happen that the watched process will not be terminated imediately (or before finished).

              Such Async processing is available for EJB3.1

              • 4. Re: Method Timeout JBoss EAP 5.1
                csariedd

                Ouch, so that explains the odd behavior I'm getting when I attempt to cancel the future when a timeoutException occurs.

                It seems to me the future might never gets canceled. (I have seen some cases where it did)

                 

                I even attempted to shutdown the executor that didn't help.

                 

                /** snippet from a class that handles request */
                 ExecutorService executor = Executors.newFixedThreadPool( 1 );
                
                      FutureTask< Status > future = (FutureTask)
                         executor.submit(
                            new Callable< Status >() {
                               public Status call() {
                                  return action();
                               }
                         }
                      );
                
                 try {
                
                    Status result = future.get( timeout, TimeUnit.MILLISECONDS );
                
                  } catch( TimeoutException te ) {
                
                    future.cancel( true );
                    executor.shutdown();
                
                   try {
                      executor.awaitTermination( 100, TimeUnit.NANOSECONDS ); /** I tried different combination of timeout it still didn't have an effect */
                
                   } catch (InterruptedException ignored) {
                      executor.shutdownNow();
                   }
                
                  } finally {
                   return result; /** no matter what notify consumer of what's going on */
                  }
                
                

                 

                I noticed that action keeps on going, and the consumer recieves the correct timeout error! Not sure what's going on there.