I have an EJB A
that invokes EJB B
. The UI should not wait for more than 30 seconds for a response. If some data is missing, it should return a partial response.
How can I define a timeout (time limit of 30 seconds) on EJB B
?
I can define EJB B
as Asynchronous
that returns Future
, and then do Future.get(30, TimeUnit.SECONDS)
.
But is it the best solution?
thank you
P.S. I use glassfish 3.1
I would suggest using the transaction timeout for this.
I don't think there is a standard way of configuring it so it would depend on the application server. I assume you want to set it specifically per class or method.
For WebLogic you can specify it in "weblogic-ejb-jar.xml" in the "transaction-descriptor" or use the annotation "@TransactionTimeoutSeconds".
http://docs.oracle.com/cd/E12839_01/web.1111/e13719/ejb_jar_ref.htm#i1506703
http://docs.oracle.com/cd/E21764_01/web.1111/e13720/annotations.htm#i1438354
For JBoss AS you could set the transaction timeout using the annotation "@TransactionTimeout" or in "jboss.xml".
https://community.jboss.org/wiki/TransactionTimeout
I am sure there are similar configuration options in every application server.