Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/channels/Selector/SelectAndClose.java
38828 views
/*1* Copyright (c) 2004, 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 500407725* @summary Check blocking of select and close26*/2728import java.nio.channels.*;29import java.io.IOException;3031public class SelectAndClose {32static Selector selector;33static boolean awakened = false;34static boolean closed = false;3536public static void main(String[] args) throws Exception {37selector = Selector.open();3839// Create and start a selector in a separate thread.40new Thread(new Runnable() {41public void run() {42try {43selector.select();44awakened = true;45} catch (IOException e) {46System.err.println(e);47}48}49}).start();5051// Wait for above thread to get to select() before we call close.52Thread.sleep(3000);5354// Try to close. This should wakeup select.55new Thread(new Runnable() {56public void run() {57try {58selector.close();59closed = true;60} catch (IOException e) {61System.err.println(e);62}63}64}).start();6566// Wait for select() to be awakened, which should be done by close.67Thread.sleep(3000);6869if (!awakened)70selector.wakeup();7172// Correct result is true and true73if (!awakened)74throw new RuntimeException("Select did not wake up");75if (!closed)76throw new RuntimeException("Selector did not close");77}78}798081