0

I'm trying to make a JavaEE application production-ready on IBM WebSphere Application Server v. 8.5.5.4.

In case of web requests that result in too long calculations (for any reasons from unexpectdly big amounts of data to programming errors that result in endless looping), I would like to abort them after some time.

I couldn't find anything in the Web Sphere documentation (as usual, I must say). Everything I found so far on StackOverflow and elsewhere is not suitable for my situation:

  • Client Side Timeout: Not what I want, since I want to save server resources by killing (almost) endlessly looping threads.
  • Container Managed Transactions: I'm not using them, so setting timeouts here leads to nowhere.
  • Connection Timeout (JDBC Datasource): I'm not worried about database requests taking too long, but about my business logic looping forever.
  • WAS Stuck Thread Detection: As far as I can comprehend, this can only be used to print warnings.

I would go for any server side solution; it could be some WAS setting or some plain JavaEE/Servlet configuration I didn't know about.

Any WebSphere experts out here? Thank you for your help!

EDIT:

Actually a duplicate of How do you kill a thread in Java? and How to timeout a thread. Asking this question I assumed that this is possible in Java, and therefore there must be some feature for it in WebSphere.

Community
  • 1
  • 1
Kamaruni
  • 68
  • 8

1 Answers1

2

There is no way to (safely) forcibly stop or "timeout" a running thread in any JVM, regardless of whether the JVM is an application server like WebSphere. This is particularly true for threads that are stuck in pure "computation" (if the thread eventually hits an interruption point then Thread.interrupt might be usable; for example, a hung thread notification listener might be able to do it, but there is no builtin support for that in WebSphere). Your best option is to write "cooperative" interrupt/cancellation; that is, you need to explicitly write code that periodically checks if it has been running too long and to cancel itself. As for unintentional infinite loops, your only defense is robust/well-tested code.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • Great! Thanks to your answer, I figured out that I was looking for a WebSphere feature that cannot exist. So after all, it's not always WebSphere's fault ;) – Kamaruni Jun 08 '15 at 13:25