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.Status003Test</code>.
033: */
034: public class Status003Debuggee extends SyncDebuggee {
035:
036: static Status003Debuggee status003DebuggeeThis;
037: static volatile boolean status003DebuggeeThreadStarted = 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: Status003Debuggee: START");
053: status003DebuggeeThis = this ;
054:
055: String status003DebuggeeThreadName = "Status003DebuggeeThread";
056: Status003Debuggee_Thread status003DebuggeeThread = new Status003Debuggee_Thread(
057: status003DebuggeeThreadName);
058:
059: status003DebuggeeThread.start();
060:
061: while (!status003DebuggeeThreadStarted) {
062: waitMlsecsTime(1000);
063: }
064: logWriter
065: .println("--> Debuggee: Status003Debuggee: will sleep for 10 seconds");
066: waitMlsecsTime(10000); // to make sure that status003DebuggeeThread is sleeping
067:
068: synchronizer.sendMessage(status003DebuggeeThreadName);
069: synchronizer.receiveMessage(); // signal to finish
070:
071: try {
072: status003DebuggeeThread.interrupt();
073: } catch (Throwable thrown) {
074: // ignore
075: }
076: while (status003DebuggeeThread.isAlive()) {
077: waitMlsecsTime(100);
078: }
079:
080: logWriter.println("--> Debuggee: Status003Debuggee: FINISH");
081: System.exit(0);
082: }
083:
084: public static void main(String[] args) {
085: runDebuggee(Status003Debuggee.class);
086: }
087: }
088:
089: class Status003Debuggee_Thread extends Thread {
090:
091: public Status003Debuggee_Thread(String name) {
092: super (name);
093: }
094:
095: public void run() {
096: Status003Debuggee parent = Status003Debuggee.status003DebuggeeThis;
097: parent.logWriter.println("--> Thread: " + getName()
098: + ": started...");
099: long mlsecTimeToSleep = 1000 * 60 * 3;
100: parent.logWriter.println("--> Thread: " + getName()
101: + ": will wait " + mlsecTimeToSleep + " mlsecs");
102: Status003Debuggee.status003DebuggeeThreadStarted = true;
103: Object ObjectForWait = new Object();
104: synchronized (ObjectForWait) {
105: try {
106: ObjectForWait.wait(mlsecTimeToSleep);
107: } catch (Throwable throwable) {
108: // ignore
109: }
110: }
111: parent.logWriter.println("--> Thread: " + getName()
112: + ": is finishibg...");
113: }
114: }
|