Reputation: 3795
I'm writing a single threaded program, which sometimes calls blocking methods (ie process.waitFor
).
Can I be sure that the interrupted status of my thread is never set? Are there other conditions under which the JVM or the JRE standard library might decide to set the interrupt flag on my thread?
It seems true, but I couldn't find any mention about it in the Java docs.
Upvotes: 0
Views: 848
Reputation: 1643
If your application does not create any "Java" (java.lang.Thread) threads then I believe you can safely assume that your main thread will never be interrupted, see this dW article by Brian Goetz. Of course it is always possible that some library you're using could create threads and could potentially call interrupt() on your main thread, but it isn't likely.
In the end, I think you need to consider your requirements. The main purpose of the interrupt support in threads is so that tasks (threads) can be cancelled and so that applications can shutdown cleanly, even if some threads are suspended in blocking calls.
Upvotes: 3