0N/A/*
6410N/A * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
6410N/A * @bug 4176355 7181748
0N/A * @summary Suspending a ThreadGroup that contains the current thread has
0N/A * unpredictable results.
0N/A */
0N/A
0N/Apublic class Suspend implements Runnable {
0N/A
6410N/A private static volatile int count = 0;
6410N/A private static final ThreadGroup group = new ThreadGroup("");
6410N/A private static final Thread first = new Thread(group, new Suspend());
6410N/A private static final Thread second = new Thread(group, new Suspend());
0N/A
0N/A public void run() {
0N/A while (true) {
0N/A try {
6410N/A Thread.sleep(100);
6410N/A if (Thread.currentThread() == first) {
6410N/A if (second.isAlive()) {
6410N/A group.suspend();
6410N/A }
6410N/A } else {
0N/A count++;
6410N/A }
6410N/A } catch (InterruptedException e) {
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
6410N/A // Launch two threads as part of the same thread group
6410N/A first.start();
6410N/A second.start();
6410N/A
6410N/A // Wait for the thread group suspend to be issued
6410N/A while (!first.isAlive() || !second.isAlive()) {
6410N/A Thread.sleep(100);
6410N/A }
6410N/A Thread.sleep(1000);
6410N/A // Suppose, the thread group is now suspended
6410N/A
6410N/A count = 0;
6410N/A Thread.sleep(1000);
6410N/A
6410N/A // Increment of the count indicates that the second thread is still running
0N/A boolean failed = (count > 1);
6410N/A first.stop();
6410N/A second.stop();
6410N/A if (failed) {
0N/A throw new RuntimeException("Failure.");
6410N/A }
0N/A }
0N/A}