Path: blob/master/test/jdk/java/nio/channels/SocketChannel/Open.java
41154 views
/*1* Copyright (c) 2002, 2017, 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*/2223import java.net.SocketException;24import java.nio.channels.DatagramChannel;25import java.nio.channels.Pipe;26import java.nio.channels.ServerSocketChannel;27import java.nio.channels.SocketChannel;28import java.nio.channels.spi.SelectorProvider;2930public class Open {3132static void test1() {33for (int i=0; i<11000; i++) {34try {35SocketChannel sc = SocketChannel.open();36} catch (Exception e) {37// Presumably "Too many open files"38}39}40}41static void test2() {42for (int i=0; i<11000; i++) {43try {44DatagramChannel sc = DatagramChannel.open();45} catch (Exception e) {46// Presumably "Too many open files"47}48}49}50static void test3() {51SelectorProvider sp = SelectorProvider.provider();52for (int i=0; i<11000; i++) {53try {54Pipe p = sp.openPipe();55} catch (Exception e) {56// Presumably "Too many open files"57}58}59}60static void test4() {61for (int i=0; i<11000; i++) {62try {63ServerSocketChannel sc = ServerSocketChannel.open();64} catch (Exception e) {65// Presumably "Too many open files"66}67}68}6970public static void main(String[] args) throws Exception {7172// Load necessary classes ahead of time73DatagramChannel dc = DatagramChannel.open();74Exception se = new SocketException();75SelectorProvider sp = SelectorProvider.provider();76Pipe p = sp.openPipe();77ServerSocketChannel ssc = ServerSocketChannel.open();7879test1();80test2();81test3();82test4();83}8485}868788