When Thread.interrupt is executed for a thread in Selector.select(), the interrupted thread just terminates.
REPRODUCE :
Compile the attached test program and launch "java BID5100121_1"
---Test Program : BID5100121_1.java -----
import java.net.*;
import java.io.*;
import java.util.*;
import java.nio.*;
import java.nio.channels.*;
public class BID5100121_1 extends Thread {
static Thread main_thread;
private int type;
static boolean flag = false;
public static void main( String args[] ) throws Exception {
if ( args.length == 0 ) {
flag = true;
}
Selector selector = Selector.open();
ServerSocketChannel server = ServerSocketChannel.open();
server.configureBlocking(false);
InetSocketAddress addr = new InetSocketAddress(9998);
server.socket().bind(addr);
server.register( selector, SelectionKey.OP_ACCEPT);
main_thread = Thread.currentThread();
new BID5100121_1(1).start();
String message=null;
try {
int n = selector.select();
if ( n == 0 ) {
System.out.println("TimeOut");
}
else {
System.out.println("select():"+n);
}
}
catch(Throwable e) {
e.printStackTrace();
}
System.out.println("end");
}
BID5100121_1( int t ) {
type = t;
}
public void run() {
try {
Thread.sleep(3000);
}
catch(Exception e ) {
e.printStackTrace();
}
System.out.println("interrupt");
try {
main_thread.interrupt();
}
catch(Exception e ) {
e.printStackTrace();
}
}
}
-----------------------------------------
PROBLEM :
The main thread executes select() and another thread interrupts the main thread.
Launching "java BID5100121", I see the following messages.
chive[42]% java BID5100121_1
interrupt
chive[43]%
It seems that the interrupted main thread just terminates and following operations are cancelled.
REQUEST :
IOException should appear, or select() should return something (ex. returns 0)