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.5 $
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.framework.TestErrorException;
031: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
032: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
033:
034: /**
035: * The class specifies debuggee for
036: * <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.CurrentContendedMonitorTest</code>.
037: * This debuggee starts the tested thread <code>TESTED_THREAD</code> which
038: * invokes <code>wait()</code>.
039: */
040: public class CurrentContendedMonitorDebuggee extends SyncDebuggee {
041:
042: public static final String TESTED_THREAD = "TestedThread";
043:
044: static Object waitForStart = new Object();
045:
046: static Object waitForFinish = new Object();
047:
048: DebuggeeThread thrd;
049:
050: public void run() {
051: thrd = new DebuggeeThread(TESTED_THREAD, logWriter,
052: synchronizer);
053: try {
054: synchronized (waitForStart) {
055: thrd.start();
056: try {
057: waitForStart.wait();
058: } catch (InterruptedException e) {
059: throw new TestErrorException(e);
060: }
061: }
062: logWriter.println("thread started");
063:
064: synchronized (waitForStart) {
065: synchronizer
066: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
067: }
068:
069: synchronizer
070: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
071: } finally {
072: if (thrd.isAlive()) {
073: logWriter.println("Thread is alive. Interrupt thread");
074: thrd.interrupt();
075: }
076: }
077: }
078:
079: class DebuggeeThread extends Thread {
080:
081: LogWriter logWriter;
082:
083: DebuggeeSynchronizer synchronizer;
084:
085: public DebuggeeThread(String name, LogWriter logWriter,
086: DebuggeeSynchronizer synchronizer) {
087: super (name);
088: this .logWriter = logWriter;
089: this .synchronizer = synchronizer;
090: }
091:
092: public void run() {
093:
094: synchronized (CurrentContendedMonitorDebuggee.waitForFinish) {
095:
096: synchronized (CurrentContendedMonitorDebuggee.waitForStart) {
097: CurrentContendedMonitorDebuggee.waitForStart
098: .notifyAll();
099:
100: try {
101: logWriter.println("Thread waits on object..");
102: CurrentContendedMonitorDebuggee.waitForStart
103: .wait();
104: } catch (InterruptedException e) {
105: logWriter.println("Expected " + e);
106: //synchronizer.sendMessage(e.toString());
107: }
108: }
109: }
110: }
111: }
112:
113: public static void main(String[] args) {
114: runDebuggee(CurrentContendedMonitorDebuggee.class);
115: }
116: }
|