3048N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3048N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3048N/A * This code is free software; you can redistribute it and/or modify it 3048N/A * under the terms of the GNU General Public License version 2 only, as 3048N/A * published by the Free Software Foundation. 3048N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3048N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3048N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3048N/A * version 2 for more details (a copy is included in the LICENSE file that 3048N/A * You should have received a copy of the GNU General Public License version 3048N/A * 2 along with this work; if not, write to the Free Software Foundation, 3048N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3048N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3048N/A * or visit www.oracle.com if you need additional information or have any 3048N/A * @summary Ensure ClosedByInterruptException is thrown when I/O operation 3048N/A * interrupted by Thread.interrupt 4224N/A // test with 1-16 concurrent threads 4224N/A for (
int i=
1; i<=
16; i++) {
3048N/A * Starts "nThreads" that do I/O on the given file concurrently. Continuously 3048N/A * interrupts one of the threads to cause the file to be closed and 3048N/A * ClosedByInterruptException to be thrown. The other threads should "fail" with 3048N/A * ClosedChannelException (or the more specific AsynchronousCloseException). 3048N/A // give time for threads to start 3048N/A // interrupt thread until channel is closed 3048N/A * A task that continuously reads or writes to random areas of a file 3048N/A * until the channel is closed. An "interruptible" task expects the 3048N/A * channel to be closed by an interupt, a "non-interruptible" thread 3048N/A // give the interruptible thread a chance