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 Vitaly A. Provodin
021: * @version $Revision: 1.2 $
022: */
023:
024: /**
025: * Created on 24.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028: import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
029: import org.apache.harmony.jpda.tests.framework.LogWriter;
030: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
031: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
032:
033: /**
034: * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.OwnedMonitorsTest</code>.
035: * This debuggee starts the tested thread <code>TESTED_THREAD</code> which
036: * synchronized with test via the <code>SGNL_READY</code> and
037: * <code>SGNL_CONTINUE</code> signals.
038: */
039: public class OwnedMonitorsDebuggee extends SyncDebuggee {
040:
041: public static final String TESTED_THREAD = "TestedThread";
042:
043: static Object waitForStart = new Object();
044: static Object waitForFinish = new Object();
045:
046: public void run() {
047: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
048: logWriter, synchronizer);
049:
050: synchronized (waitForStart) {
051: thrd.start();
052: try {
053: waitForStart.wait();
054: } catch (InterruptedException e) {
055:
056: }
057: }
058:
059: synchronized (waitForFinish) {
060: logWriter.println("thread is finished");
061: }
062: }
063:
064: class DebuggeeThread extends Thread {
065:
066: LogWriter logWriter;
067: DebuggeeSynchronizer synchronizer;
068:
069: public DebuggeeThread(String name, LogWriter logWriter,
070: DebuggeeSynchronizer synchronizer) {
071: super (name);
072: this .logWriter = logWriter;
073: this .synchronizer = synchronizer;
074: }
075:
076: public void run() {
077:
078: synchronized (OwnedMonitorsDebuggee.waitForFinish) {
079:
080: synchronized (OwnedMonitorsDebuggee.waitForStart) {
081:
082: OwnedMonitorsDebuggee.waitForStart.notifyAll();
083:
084: logWriter.println(getName() + ": started");
085: synchronizer
086: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
087:
088: logWriter.println(getName()
089: + ": wait for SGNL_CONTINUE");
090: synchronizer
091: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
092: logWriter.println(getName() + ": finished");
093: }
094: }
095: }
096: }
097:
098: public static void main(String[] args) {
099: runDebuggee(OwnedMonitorsDebuggee.class);
100: }
101: }
|