jdk/test/java/nio/channels/Selector/LotsOfChannels.java
changeset 5970 d4e98bbfb0be
parent 5506 202f599c92aa
child 7668 d4a77089c587
equal deleted inserted replaced
5968:4e9dd25279c7 5970:d4e98bbfb0be
    33 import java.nio.*;
    33 import java.nio.*;
    34 import java.nio.channels.*;
    34 import java.nio.channels.*;
    35 
    35 
    36 public class LotsOfChannels {
    36 public class LotsOfChannels {
    37 
    37 
    38     private final static int PIPES_COUNT = 1900;
    38     private final static int PIPES_COUNT = 256;
    39     private final static int BUF_SIZE = 8192;
    39     private final static int BUF_SIZE = 8192;
    40     private final static int LOOPS = 10;
    40     private final static int LOOPS = 10;
    41 
    41 
    42     public static void main(String[] argv) throws Exception {
    42     public static void main(String[] argv) throws Exception {
    43 
       
    44 
       
    45         String os = System.getProperty("os.name");
       
    46         if (!(os.equals("Windows NT")
       
    47            || os.equals("Windows 2000")
       
    48            || os.equals("Windows XP")))
       
    49             return;
       
    50 
       
    51         Pipe[] pipes = new Pipe[PIPES_COUNT];
    43         Pipe[] pipes = new Pipe[PIPES_COUNT];
    52         Pipe pipe = Pipe.open();
    44         Pipe pipe = Pipe.open();
    53         Pipe.SinkChannel sink = pipe.sink();
    45         Pipe.SinkChannel sink = pipe.sink();
    54         Pipe.SourceChannel source = pipe.source();
    46         Pipe.SourceChannel source = pipe.source();
    55         Selector sel = Selector.open();
    47         Selector sel = Selector.open();
    70             sink.write(ByteBuffer.allocate(BUF_SIZE));
    62             sink.write(ByteBuffer.allocate(BUF_SIZE));
    71             int x = sel.selectNow();
    63             int x = sel.selectNow();
    72             sel.selectedKeys().clear();
    64             sel.selectedKeys().clear();
    73             source.read(ByteBuffer.allocate(BUF_SIZE));
    65             source.read(ByteBuffer.allocate(BUF_SIZE));
    74         }
    66         }
       
    67 
       
    68         for (int i = 0; i < PIPES_COUNT; i++ ) {
       
    69             pipes[i].sink().close();
       
    70             pipes[i].source().close();
       
    71         }
       
    72         pipe.sink().close();
       
    73         pipe.source().close();
    75         sel.close();
    74         sel.close();
    76     }
    75     }
    77 }
    76 }