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.3 $
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.Status005Test</code>.
033: */
034: public class Status005Debuggee extends SyncDebuggee {
035:
036: static Status005Debuggee status005DebuggeeThis;
037: static volatile boolean status005DebuggeeThreadStarted = false;
038:
039: static Object lockObject = new Object();
040:
041: static Object waitTimeObject = new Object();
042:
043: static void waitMlsecsTime(long mlsecsTime) {
044: synchronized (waitTimeObject) {
045: try {
046: waitTimeObject.wait(mlsecsTime);
047: } catch (Throwable throwable) {
048: // ignore
049: }
050: }
051: }
052:
053: public void run() {
054: logWriter.println("--> Debuggee: Status005Debuggee: START");
055: status005DebuggeeThis = this ;
056:
057: String status005DebuggeeThreadName = "Status005DebuggeeThread";
058: Status005Debuggee_Thread status005DebuggeeThread = new Status005Debuggee_Thread(
059: status005DebuggeeThreadName);
060:
061: synchronized (lockObject) {
062: logWriter
063: .println("--> Debuggee: Status005Debuggee: has entered in synchronized(lockObject) block");
064: status005DebuggeeThread.start();
065:
066: while (!status005DebuggeeThreadStarted) {
067: waitMlsecsTime(1000);
068: }
069: logWriter
070: .println("--> Debuggee: Status005Debuggee: will sleep for 10 seconds");
071: waitMlsecsTime(10000); // to make sure that status005DebuggeeThread is sleeping
072:
073: synchronizer.sendMessage(status005DebuggeeThreadName);
074: synchronizer.receiveMessage(); // signal to finish
075: }
076: logWriter
077: .println("--> Debuggee: Status005Debuggee: has exited from synchronized(lockObject) block");
078:
079: while (status005DebuggeeThread.isAlive()) {
080: waitMlsecsTime(100);
081: }
082:
083: logWriter.println("--> Debuggee: Status005Debuggee: FINISH");
084: System.exit(0);
085: }
086:
087: public static void main(String[] args) {
088: runDebuggee(Status005Debuggee.class);
089: }
090: }
091:
092: class Status005Debuggee_Thread extends Thread {
093:
094: public Status005Debuggee_Thread(String name) {
095: super (name);
096: }
097:
098: public void run() {
099: Status005Debuggee parent = Status005Debuggee.status005DebuggeeThis;
100: parent.logWriter.println("--> Thread: " + getName()
101: + ": started...");
102: parent.logWriter
103: .println("--> Thread: "
104: + getName()
105: + ": will try to enter in synchronized(lockObject) block");
106: Status005Debuggee.status005DebuggeeThreadStarted = true;
107: synchronized (Status005Debuggee.lockObject) {
108: parent.logWriter
109: .println("--> Thread: "
110: + getName()
111: + ": has entered in synchronized(lockObject) block");
112: }
113: parent.logWriter.println("--> Thread: " + getName()
114: + ": is finishibg...");
115: }
116: }
|