As the title says I need a way to stop or interrupt a thread that is blocked waiting on an input from the socket.
You could simply close() the IO stream/socket from another thread. Then, you could check on a volatile boolean field if the resulting IOException is due the close or something else. I think the close might result in an java.net.SocketException: Socket closed
exception.
Thread.interrupt() should be the method you're looking for. Be sure that your input-accessing methods also check for InterruptedException and ClosedByInterruptException.
Also look at the corresponding page in the Sun Concurrency Tutorial, as another solution suggests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With