test/jdk/java/nio/channels/Selector/RegisterDuringSelect.java
changeset 51077 9baa91bc7567
parent 49802 8ac08fa69f00
child 51602 dbb0e798deeb
equal deleted inserted replaced
51076:7c96d1e40280 51077:9baa91bc7567
    26  * @summary Test that channels can be registered, interest ops can changed,
    26  * @summary Test that channels can be registered, interest ops can changed,
    27  *          and keys cancelled while a selection operation is in progress.
    27  *          and keys cancelled while a selection operation is in progress.
    28  */
    28  */
    29 
    29 
    30 import java.io.IOException;
    30 import java.io.IOException;
       
    31 import java.nio.channels.ClosedSelectorException;
    31 import java.nio.channels.Pipe;
    32 import java.nio.channels.Pipe;
    32 import java.nio.channels.SelectionKey;
    33 import java.nio.channels.SelectionKey;
    33 import java.nio.channels.Selector;
    34 import java.nio.channels.Selector;
    34 import java.util.concurrent.Callable;
    35 import java.util.concurrent.Callable;
    35 import java.util.concurrent.ExecutorService;
    36 import java.util.concurrent.ExecutorService;
    42     static Callable<Void> selectLoop(Selector sel, Phaser barrier) {
    43     static Callable<Void> selectLoop(Selector sel, Phaser barrier) {
    43         return new Callable<Void>() {
    44         return new Callable<Void>() {
    44             @Override
    45             @Override
    45             public Void call() throws IOException {
    46             public Void call() throws IOException {
    46                 for (;;) {
    47                 for (;;) {
    47                     sel.select();
    48                     try {
       
    49                         sel.select();
       
    50                     } catch (ClosedSelectorException ignore) {
       
    51                         return null;
       
    52                     }
    48                     if (sel.isOpen()) {
    53                     if (sel.isOpen()) {
    49                         barrier.arriveAndAwaitAdvance();
    54                         barrier.arriveAndAwaitAdvance();
       
    55                         System.out.println("selectLoop advanced ...");
    50                     } else {
    56                     } else {
    51                         // closed
    57                         // closed
    52                         return null;
    58                         return null;
    53                     }
    59                     }
    54                 }
    60                 }
   105         // ensure selectLoop completes without exception
   111         // ensure selectLoop completes without exception
   106         result.get();
   112         result.get();
   107 
   113 
   108     }
   114     }
   109 }
   115 }
       
   116