Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002a.java
40955 views
/*1* Copyright (c) 2002, 2018, 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*/2223package nsk.jdb.thread.thread002;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdb.*;2829import java.io.*;3031/* This is debuggee aplication */32public class thread002a {33public static void main(String args[]) {34thread002a _thread002a = new thread002a();35System.exit(thread002.JCK_STATUS_BASE + _thread002a.runIt(args, System.out));36}3738static void lastBreak () {}39static int numThreads = 5; // number of threads40static Thread holder [] = new Thread[numThreads];4142static Object waitnotify = new Object();4344public int runIt(String args[], PrintStream out) {45JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);46Log log = new Log(out, argumentHandler);4748Lock lock = new Lock();4950try {51lock.setLock();52for (int i = 0; i < numThreads ; i++) {53holder[i] = new MyThread(lock, "MyThread#" + i);54synchronized (waitnotify) {55holder[i].start();56waitnotify.wait();57}58}59} catch (Exception e) {60System.err.println("TEST ERROR: Caught unexpected Exception while waiting in main thread: " +61e.getMessage());62System.exit(thread002.FAILED);63}6465lastBreak(); // When jdb stops here, there should be 5 running MyThreads.66lock.releaseLock();6768for (int i = 0; i < numThreads ; i++) {69if (holder[i].isAlive()) {70try {71holder[i].join(argumentHandler.getWaitTime() * 60000);72} catch (InterruptedException e) {73throw new Failure("Unexpected InterruptedException catched while waiting for join of: " + holder[i]);74}75}76}7778log.display("Debuggee PASSED");79return thread002.PASSED;80}8182}8384class Lock {85boolean lockSet;8687synchronized void setLock() throws InterruptedException {88while (lockSet == true)89wait();90lockSet = true;91}9293synchronized void releaseLock() {94if (lockSet == true) {95lockSet = false;96notify();97}98}99}100101class MyThread extends Thread {102103Lock lock;104String name;105106MyThread (Lock l, String name) {107this.lock = l;108this.name = name;109}110111public void run() {112synchronized (thread002a.waitnotify) {113thread002a.waitnotify.notifyAll();114}115try {116lock.setLock();117} catch(Exception e) {118System.err.println("TEST ERROR: Caught unexpected Exception while waiting in MyThread: " +119e.getMessage());120System.exit(thread002.FAILED);121}122lock.releaseLock();123}124}125126127