001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anatoly F. Bondarenko
021: * @version $Revision: 1.2 $
022: */
023:
024: /**
025: * Created on 31.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028: // import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
029: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
030:
031: /**
032: * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.Status004Test</code>.
033: */
034: public class Status004Debuggee extends SyncDebuggee {
035:
036: static Status004Debuggee status004DebuggeeThis;
037: static volatile boolean status004DebuggeeThreadStarted = false;
038:
039: static Object waitTimeObject = new Object();
040:
041: static void waitMlsecsTime(long mlsecsTime) {
042: synchronized (waitTimeObject) {
043: try {
044: waitTimeObject.wait(mlsecsTime);
045: } catch (Throwable throwable) {
046: // ignore
047: }
048: }
049: }
050:
051: public void run() {
052: logWriter.println("--> Debuggee: Status004Debuggee: START");
053: status004DebuggeeThis = this ;
054:
055: String status004DebuggeeThreadName = "Status004DebuggeeThread";
056: Status004Debuggee_Thread status004DebuggeeThread = new Status004Debuggee_Thread(
057: status004DebuggeeThreadName);
058:
059: status004DebuggeeThread.start();
060:
061: while (!status004DebuggeeThreadStarted) {
062: waitMlsecsTime(1000);
063: }
064: logWriter
065: .println("--> Debuggee: Status004Debuggee: will sleep for 10 seconds");
066: waitMlsecsTime(10000); // to make sure that status004DebuggeeThread is sleeping
067:
068: synchronizer.sendMessage(status004DebuggeeThreadName);
069: synchronizer.receiveMessage(); // signal to finish
070:
071: try {
072: status004DebuggeeThread.interrupt();
073: } catch (Throwable thrown) {
074: // ignore
075: }
076: while (status004DebuggeeThread.isAlive()) {
077: waitMlsecsTime(100);
078: }
079:
080: logWriter.println("--> Debuggee: Status004Debuggee: FINISH");
081: System.exit(0);
082: }
083:
084: public static void main(String[] args) {
085: runDebuggee(Status004Debuggee.class);
086: }
087: }
088:
089: class Status004Debuggee_Thread extends Thread {
090:
091: public Status004Debuggee_Thread(String name) {
092: super (name);
093: }
094:
095: public void run() {
096: Status004Debuggee parent = Status004Debuggee.status004DebuggeeThis;
097: parent.logWriter.println("--> Thread: " + getName()
098: + ": started...");
099: parent.logWriter.println("--> Thread: " + getName()
100: + ": will wait UNDEFINITELY");
101: Status004Debuggee.status004DebuggeeThreadStarted = true;
102: Object ObjectForWait = new Object();
103: synchronized (ObjectForWait) {
104: try {
105: ObjectForWait.wait();
106: } catch (Throwable throwable) {
107: // ignore
108: }
109: }
110: parent.logWriter.println("--> Thread: " + getName()
111: + ": is finishibg...");
112: }
113: }
|