Can I start a thread that is blocked due to a call to DatagramSocket.receive ()?

I have a thread that is blocked in a UDP packet, and I need to tell him to forget about this packet and do something else before the receive timeout occurs. Is there any way to do this?

+5
source share
3 answers

Use the DatagramChannel to read your UDP packets and interrupt the reading stream. According to the documentation of Thread.interrupt (and the DatagramChannel), the read operation then throws a ClosedByInterruptException.

+3
source

JB . NIO, AFAIK /. - TCP, . , . NIO .

+2

- , , - . (n-1) Thread.isInterrupted().

0

All Articles