Is there any timeout setting on an EJB components?

803 Views Asked by At

Is there any timeout setting on an EJB component?

In this EJB component, there is a code running sql for more than 30 minutes. Hence, timeout is trigger, every sql statements are rolled back.

I have set JPA timeout to 1 hour but seems there is another additional setting in EJB.

Tqs. Jimmy

1

There are 1 best solutions below

3
On

Since EJB 3.1 this is achievable with @Asyncrhonous ( http://docs.oracle.com/javaee/7/api/javax/ejb/Asynchronous.html )

@Asynchronous
public Future<ResultObject> longRunningMethod () {

}

Then you can call it with

Future<ResultObject> result = ejb.longRunningMethod();
result.get(15, TimeUnit.SECONDS);

Note that the default transaction mode for the longRunningMethod will be REQUIRED_NEW. This can make things tricky.

Apart from this, all the containers provide a way to set transaction timeout. But this doesn't work as expected. The method doesn't return, it is just marked failed after the timeout duration and throws transaction timeout exception after the method completes and not immediately after the timeout is exceeded.

In general, if your database transaction runs longer than 30 min. and ejb method is not the way to go. This seems like a batch process.