Reputation: 51
I have a simple Java Servlet application running. It has a few endpoints. Although the service is pretty fast, there are a few requests that I get which sometimes take more time than expected. What will be the best way to kill any requests that take say more than ~20 secs to process?
Upvotes: 4
Views: 1970
Reputation: 44952
If you want to interrupt the request handling thread and you are using Tomcat you can try Stuck Thread Detection Valve:
interruptThreadThreshold
Minimum duration in seconds after which a stuck thread should be interrupted to attempt to "free" it.
Note that there's no guarantee that the thread will get unstuck. This usually works well for threads stuck on I/O or locks, but is probably useless in case of infinite loops.
Default is -1 which disables the feature. To enable it, the value must be greater or equal to threshold.
It might be better to implement Circuit Breaker in the client as interruptThreadThreshold
is not guaranteed to work for all scenarios.
Upvotes: 4