Aviad S.
Aviad S.

Reputation: 171

timeout a job on jboss

i'm running jboss AS 4.2 with java 1.6 and my problem is as follows: our application is distributed as an ear and a war containing some servlets. these servlets call the needed EJBs which do some processing and then return the result.

i'm looking for a way to determine a timeout, which in case the processing takes too much time, and it'll just return and end the processing (the processing involves several EJBs).

i can use ThreadLocal and add some code that will check at the beginning of each method if it exceeded the time - but is there some other mechanism i can use without adding such code to my application?

any idea / reference will be good.

Upvotes: 2

Views: 106

Answers (1)

Peter Butkovic
Peter Butkovic

Reputation: 12149

There might be different ways, but very first thing comming to my mind based on your requiremens are interceptors.

So that you would intercept all your problematic (possibly long taking calls) and throw exception in case they exceeded the time.

And yes, threadlocal could do the job for keeping the start time (In case you don't use asynchronous stateless session bean calls).

To get some idea, of what interceptors are capable of, see: http://www.adam-bien.com/roller/abien/entry/interceptors_ejb_3_for_absolute

The main advantage of this solution is that you would have clear separation of timeout functionality (in Interceptor) from your bussiness logic (in EJBs).

Upvotes: 1

Related Questions