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