Saul Tocsin wrote:
I've spent time browsing this forum, but this is my first post.
Saul Tocsin wrote:
I am trying to think through a scenario that sees a long-running thread, started by an Executor, get "permanently" hung. We don't know why this happens. Maybe it's blocked in I/O. Consider it a "given." Supposing that one can detect that the thread is hung, how can one truly cancel it?
I am familiar with the reasons behind the deprecation of Thread.stop(). The replacement approach seems to rely on the target thread (the one you want to stop) being active, i.e., the target thread periodically checks a variable that is shared with another thread and simply exits its run method. But this doesn't work for a hung thread. Moreover, it is simply not the case that a thread is always able to see a Thread.interrupt() presented by another thread.
Saul Tocsin wrote:
To wax philosphic for a moment, the JVM has in some sense replaced the real OS. That is, it functions as a mediating and insulating layer between our Java progams and the kernel. But the kernel can always cancel one of its tasks. I have the sense that the JVM is deficient in this regard and that there really is no graceful solution to certain types of thread states.
So I am interested in hearing folks' thoughts about ways of handling this problem. I looked into creating the long-running task as a Future in the hope that its cancel() method might be of some help. But even here I sense some uncertainty, e.g., the docs say: "Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason." (emphasis mine).
Henry Wong wrote:
Not sure what you mean by "the kernel can always cancel one of its tasks". All the issues mentioned, like hung on I/O also applies at the OS layer, and the same techniques also needs to be used. Or do you mean something specific that hasn't been mentioned yet?
Saul Tocsin wrote:
The difficulty here is that I don't have much control over the I/O layer. Imagine that the thread in question is in the "business" layer and that it calls into the lower DAO/Persistence layer via some kind of CRUD procedure call connector. So I don't think that my Java thread is in a position to create and benefit from an InterruptibleChannel in presenting such a call to the layer below (please correct me if you think otherwise).
More generally, I meant the "blocked in I/O" merely as an example. The general problem is "thread hung;" don't know why, it's just not responding.
We begin by testing your absorbancy by exposing you to this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|