Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6318568

(se) Selector.select() should return something when interrupted

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_10

      Description

      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)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alanb Alan Bateman
              Reporter:
              tbaba Tadayuki Baba (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: