01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: /**
20: * @author Vitaly A. Provodin
21: * @version $Revision: 1.3 $
22: */
23:
24: /**
25: * Created on 28.02.2005
26: */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
27:
28: import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer;
29: import org.apache.harmony.jpda.tests.framework.LogWriter;
30: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
31: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
32:
33: /**
34: * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.HoldEventsTest</code>.
35: * This debuggee starts the tested thread <code>TESTED_THREAD</code>.
36: */
37: public class HoldEventsDebuggee extends SyncDebuggee {
38:
39: public static final String TESTED_THREAD = "TestedThread";
40:
41: static Object waitForStart = new Object();
42: static Object waitForFinish = new Object();
43:
44: public void run() {
45: synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
46:
47: logWriter.println("wait for SGNL_CONTINUE to start thread");
48: synchronizer
49: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
50:
51: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
52: logWriter, synchronizer);
53:
54: synchronized (waitForStart) {
55: logWriter.println("starting thread");
56: thrd.start();
57: try {
58: waitForStart.wait();
59: } catch (InterruptedException e) {
60: logWriter.println("" + e + " is cought");
61: }
62: }
63:
64: synchronized (waitForFinish) {
65: logWriter.println("thread is finished");
66: }
67: }
68:
69: class DebuggeeThread extends Thread {
70:
71: LogWriter logWriter;
72: DebuggeeSynchronizer synchronizer;
73:
74: public DebuggeeThread(String name, LogWriter logWriter,
75: DebuggeeSynchronizer synchronizer) {
76: super (name);
77: this .logWriter = logWriter;
78: this .synchronizer = synchronizer;
79: }
80:
81: public void run() {
82:
83: synchronized (HoldEventsDebuggee.waitForFinish) {
84:
85: synchronized (HoldEventsDebuggee.waitForStart) {
86:
87: HoldEventsDebuggee.waitForStart.notifyAll();
88:
89: logWriter.println(getName() + ": started");
90:
91: }
92: }
93: }
94: }
95:
96: public static void main(String[] args) {
97: runDebuggee(HoldEventsDebuggee.class);
98: }
99: }
|