C
Chris
How do I interrupt a sleeping thread without interrupting any I/O that
it may be doing?
We've got a thread that reads data using an NIO channel, goes to sleep
for a minute, wakes up and reads some more, goes to sleep, etc.
I'd like to terminate the thread quickly, but gracefully. If it's
sleeping, I'd like to wake it up and have it exit; if it's reading data,
I want it to finish and then terminate.
The trouble is that if I call Thread.interrupt(), it will properly
interrupt a Thread.sleep(), but it will also interrupt a
FileChannel.read() operation with a ClosedByInterruptException. Ideally
I'd have a way to do only the former and not the latter.
Any ideas?
it may be doing?
We've got a thread that reads data using an NIO channel, goes to sleep
for a minute, wakes up and reads some more, goes to sleep, etc.
I'd like to terminate the thread quickly, but gracefully. If it's
sleeping, I'd like to wake it up and have it exit; if it's reading data,
I want it to finish and then terminate.
The trouble is that if I call Thread.interrupt(), it will properly
interrupt a Thread.sleep(), but it will also interrupt a
FileChannel.read() operation with a ClosedByInterruptException. Ideally
I'd have a way to do only the former and not the latter.
Any ideas?