1

Basically I am doing selective repeat protocol for java and I have multiple threads for doing this. I have a thread that sends and receives, but my code gets stuck on

socket.receive(packet);

I have a timer schedule:

Timer time = new Timer(true);
time.schedule(new Timeout (i) {}, timeOut)

The timer thread gets called correctly, and the timer thread is meant to interrupt the thread waiting on receive, but the interrupt call does nothing. Can a thread interrupt not stop a blocking socket receive call? If that is the case, what else can I do?

Mustafa
  • 977
  • 3
  • 12
  • 25
  • How did you close your Thread? maybe this can help you: https://stackoverflow.com/questions/2491588/how-a-thread-should-close-itself-in-java – Yonggan Mar 25 '20 at 13:25
  • @Yonggan I have an array of threads. So in the timer thread I say threads[index].currentThread().Interrupt() but the thread in threads[index] does not throw interrupt exception or anything, stays stalled at the receive point I think – Noah Jackson Mar 25 '20 at 13:31
  • I know that it is deprecated, but lets try it with the stop() Method. If this doesnt works, try to destroy the Thread object and try if this works. – Yonggan Mar 25 '20 at 13:35
  • If you want to interrupt the read, you'll have to close the socket. If you want an exception after blocking on the read for a certain time, you need to set a read timeout. You can't use `Thread.stop()` or `Thread.destroy()`. – Kayaman Mar 25 '20 at 13:39
  • For further reference, see: https://stackoverflow.com/questions/4425350/how-to-terminate-a-thread-blocking-on-socket-io-operation-instantly perhaps you have a design issue instead? – Kayaman Mar 25 '20 at 13:47

0 Answers0