7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 * @bug 6405995
26 * @summary Unit test for selector wakeup and interruption
27 * @library .. /lib/testlibrary/
28 */
29
30 import java.io.*;
31 import java.net.*;
32 import java.nio.*;
33 import java.nio.channels.*;
34 import java.util.concurrent.CyclicBarrier;
35
36 public class Wakeup {
37
38 static void sleep(int millis) {
39 try {
40 Thread.sleep(millis);
41 } catch (InterruptedException x) {
42 x.printStackTrace();
43 }
44 }
45
46 static class Sleeper extends TestThread {
47 private static final long TIMEOUT = jdk.testlibrary.Utils.adjustTimeout(20_000);
48
49 // barrier is used to synchronize sleeper thread and checking
50 // thread which is the main thread: when go() get to the end,
51 // then start checking the sleeper's status.
52 private static CyclicBarrier barrier = new CyclicBarrier(2);
53 private static int wakeups = 0;
54 private static int waits = 0;
55
56 volatile boolean interruptBeforeSelect = false;
57 volatile boolean started = false;
58 volatile boolean wantInterrupt = false;
59 volatile boolean closed = false;
60 Object gate = new Object();
61
62 Selector sel;
63
64 Sleeper(Selector sel, boolean wantInterrupt, boolean interruptBeforeSelect) {
65 super("Sleeper", System.err);
66 this.sel = sel;
67 this.wantInterrupt = wantInterrupt;
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 * @bug 6405995
26 * @summary Unit test for selector wakeup and interruption
27 * @library .. /test/lib
28 */
29
30 import java.io.*;
31 import java.net.*;
32 import java.nio.*;
33 import java.nio.channels.*;
34 import java.util.concurrent.CyclicBarrier;
35
36 public class Wakeup {
37
38 static void sleep(int millis) {
39 try {
40 Thread.sleep(millis);
41 } catch (InterruptedException x) {
42 x.printStackTrace();
43 }
44 }
45
46 static class Sleeper extends TestThread {
47 private static final long TIMEOUT = jdk.test.lib.Utils.adjustTimeout(20_000);
48
49 // barrier is used to synchronize sleeper thread and checking
50 // thread which is the main thread: when go() get to the end,
51 // then start checking the sleeper's status.
52 private static CyclicBarrier barrier = new CyclicBarrier(2);
53 private static int wakeups = 0;
54 private static int waits = 0;
55
56 volatile boolean interruptBeforeSelect = false;
57 volatile boolean started = false;
58 volatile boolean wantInterrupt = false;
59 volatile boolean closed = false;
60 Object gate = new Object();
61
62 Selector sel;
63
64 Sleeper(Selector sel, boolean wantInterrupt, boolean interruptBeforeSelect) {
65 super("Sleeper", System.err);
66 this.sel = sel;
67 this.wantInterrupt = wantInterrupt;
|