Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/channels/Selector/LotsOfChannels.java
38828 views
/*1* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 4503092 802488325* @summary Tests that Windows Selector can use more than 63 channels26* @run main LotsOfChannels27* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=64 LotsOfChannels28* @author kladko29*/3031import java.net.*;32import java.io.*;33import java.nio.*;34import java.nio.channels.*;3536public class LotsOfChannels {3738private final static int PIPES_COUNT = 256;39private final static int BUF_SIZE = 8192;40private final static int LOOPS = 10;4142public static void main(String[] argv) throws Exception {43Pipe[] pipes = new Pipe[PIPES_COUNT];44Pipe pipe = Pipe.open();45Pipe.SinkChannel sink = pipe.sink();46Pipe.SourceChannel source = pipe.source();47Selector sel = Selector.open();48source.configureBlocking(false);49source.register(sel, SelectionKey.OP_READ);5051for (int i = 0; i< PIPES_COUNT; i++ ) {52pipes[i]= Pipe.open();53Pipe.SourceChannel sc = pipes[i].source();54sc.configureBlocking(false);55sc.register(sel, SelectionKey.OP_READ);56Pipe.SinkChannel sc2 = pipes[i].sink();57sc2.configureBlocking(false);58sc2.register(sel, SelectionKey.OP_WRITE);59}6061for (int i = 0 ; i < LOOPS; i++ ) {62sink.write(ByteBuffer.allocate(BUF_SIZE));63int x = sel.selectNow();64sel.selectedKeys().clear();65source.read(ByteBuffer.allocate(BUF_SIZE));66}6768for (int i = 0; i < PIPES_COUNT; i++ ) {69pipes[i].sink().close();70pipes[i].source().close();71}72pipe.sink().close();73pipe.source().close();74sel.close();75}76}777879