Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002a.java
40951 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.threads.threads002;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdb.*;2829import java.io.*;3031/* This is debuggee aplication */32public class threads002a {33public static void main(String args[]) {34threads002a _threads002a = new threads002a();35System.exit(threads002.JCK_STATUS_BASE + _threads002a.runIt(args, System.out));36}3738static void lastBreak () {}3940static int numThreads = 5; // number of threads41static Object waitnotify = new Object();4243public int runIt(String args[], PrintStream out) {44JdbArgumentHandler argumentHandler = new JdbArgumentHandler(args);45Log log = new Log(out, argumentHandler);4647Thread holder [] = new Thread[numThreads];48Lock lock = new Lock();4950try {51lock.setLock();52for (int i = 0; i < numThreads ; i++) {53holder[i] = new MyThread(lock);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(threads002.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 threads002.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;104MyThread (Lock l) {105this.lock = l;106}107108public void run() {109synchronized (threads002a.waitnotify) {110threads002a.waitnotify.notifyAll();111}112try {113lock.setLock();114} catch(Exception e) {115System.err.println("TEST ERROR: Caught unexpected Exception while waiting in MyThread: " +116e.getMessage());117System.exit(threads002.FAILED);118}119lock.releaseLock();120}121}122123124