cancel
Showing results for 
Search instead for 
Did you mean: 

TimeOut for EJB method calls

Former Member
0 Kudos

Hi All,

My program has a Servlet that calls EJB method. My Stateless Session Bean looks like this:

@Stateless()

public class MyBean implements SomeInterface {

@Resource

TimerService timerService;

public void myMethod() {

timerService.createTimer(timeOutMs,null);

//Do something

}

@Timeout

public void timeout(Timer timer)

Do something

Try {

timer.cancel();

}

catch (RuntimeException e) {

throw new myException(e)

}

}

Problem is like this: I am looking for approach ideas to force the EJB method to stop processing when timeout. Suppose the timeout is 1 Minute and EJB method call takes more than 1 Minute, then my EJB should throw an Exception. but it does not work. I get Exception after the complete processing is over, even though the EJB method took more than 1 Minute.

Is there a way I can force an EJB method to stop processing/timeout and return Exception?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

define a boolean field in your EJB like this:

boolean continue = true;

The timeOut method will set continue to false when called for the application server at specified timeout.

Then, your method, in "do something", must check for continue value in the main loop or in every step if it is a sequence of orders.

Former Member
0 Kudos

Thanks Esteve for your idea.

The problem is that timeOut method set continue to false after the proccessing of ejb Method is over.

somebody wrote in one forum

"Setting the transaction timeout to a particular value will not cause your

EJB method to be interrupted after that amount of time. Your EJB method wil

l proceed until completion (however long that takes) according to your code

within the method itself.

The transaction timeout setting says: "If the transaction is not completed w

ithin this amount of time, mark it for rollback, so when the method complete

s and the container later tries to complete the transaction, it will roll ba

ck rather than commit." Th

is is not unique to WAS (IBM/Websphere); it's due to the way JVM threads work.

"

That means it is not possible to force stopping the processing of the EJB Method when timeout.

Former Member
0 Kudos

You're right, I've ben confused on method name and how to use it.

Take a look on this page: [http://www.javabeat.net/articles/3-ejb-30-timer-services-an-overview-1.html|http://www.javabeat.net/articles/3-ejb-30-timer-services-an-overview-1.html]

Your EJB should extend TimedObject and the method name should be ejbTimedOut (receiving a Timer object as parameter). Then, in your business mehtod, you sould launch the timer calling the TimerService to schedule the timeout callback.