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.2 $
22: */
23:
24: /**
25: * Created on 22.02.2005
26: */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
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.StatusTest</code>.
35: * This debuggee starts the tested thread <code>TESTED_THREAD</code>.
36: */
37: public class StatusDebuggee 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: DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD,
46: logWriter, synchronizer);
47:
48: synchronized (waitForStart) {
49: thrd.start();
50: try {
51: waitForStart.wait();
52: } catch (InterruptedException e) {
53:
54: }
55: }
56:
57: synchronized (waitForFinish) {
58: logWriter.println("thread is finished");
59: }
60: }
61:
62: class DebuggeeThread extends Thread {
63:
64: LogWriter logWriter;
65: DebuggeeSynchronizer synchronizer;
66:
67: public DebuggeeThread(String name, LogWriter logWriter,
68: DebuggeeSynchronizer synchronizer) {
69: super (name);
70: this .logWriter = logWriter;
71: this .synchronizer = synchronizer;
72: }
73:
74: public void run() {
75:
76: synchronized (StatusDebuggee.waitForFinish) {
77:
78: synchronized (StatusDebuggee.waitForStart) {
79:
80: StatusDebuggee.waitForStart.notifyAll();
81:
82: logWriter.println(getName() + ": started");
83: synchronizer
84: .sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
85:
86: logWriter.println(getName()
87: + ": wait for SGNL_CONTINUE");
88: synchronizer
89: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
90: logWriter.println(getName() + ": finished");
91: }
92: }
93: }
94: }
95:
96: public static void main(String[] args) {
97: runDebuggee(StatusDebuggee.class);
98: }
99: }
|