中断网络IO的常见习惯是关闭通道。如果您需要在等待发送或接收时有效中断它,那将是一个不错的选择。
public class InterruptableUDPThread extends Thread{ private final DatagramSocket socket; public InterruptableUDPThread(DatagramSocket socket){ this.socket = socket; } @Override public void interrupt(){ super.interrupt(); this.socket.close(); }}


