1

I have a Stateless EJB containing various methods and I would like to use a timer in a function so that if the method takes longer than say 30 seconds, a timeout will occur and the caller will be notified.

I have looked at the @Schedule annotation for EJB Methods but I don't think that can serve my purpose.

TT.
  • 15,774
  • 6
  • 47
  • 88
user1107888
  • 1,481
  • 5
  • 34
  • 55

1 Answers1

0

The quickest way, if you don't need precision, is to invoke a method marked as @Asynchronous with a Future in its signature that will send a notification after 30 seconds.

The method has to be on another EJB for the @Asynchronous to be working.

Then from the caller, if the elapsed time is shorter than 30 seconds, you can cancel the operation.

TT.
  • 15,774
  • 6
  • 47
  • 88
Leonardo
  • 9,607
  • 17
  • 49
  • 89