1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 */ 22 23 /** 24 * Created on 24.02.2005 25 */ 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 /** 35 * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.OwnedMonitorsTest</code>. 36 * This debuggee starts the tested thread <code>TESTED_THREAD</code> which 37 * synchronized with test via the <code>SGNL_READY</code> and 38 * <code>SGNL_CONTINUE</code> signals. 39 */ 40 public class OwnedMonitorsDebuggee extends SyncDebuggee { 41 42 public static final String TESTED_THREAD = "TestedThread"; 43 44 static Object waitForStart = new Object(); 45 static Object waitForFinish = new Object(); 46 run()47 public void run() { 48 DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD, 49 logWriter, synchronizer); 50 51 synchronized(waitForStart){ 52 thrd.start(); 53 try { 54 waitForStart.wait(); 55 } catch (InterruptedException e) { 56 57 } 58 } 59 60 synchronized(waitForFinish){ 61 logWriter.println("thread is finished"); 62 } 63 } 64 65 class DebuggeeThread extends Thread { 66 67 LogWriter logWriter; 68 DebuggeeSynchronizer synchronizer; 69 DebuggeeThread(String name, LogWriter logWriter, DebuggeeSynchronizer synchronizer)70 public DebuggeeThread(String name, LogWriter logWriter, 71 DebuggeeSynchronizer synchronizer) { 72 super(name); 73 this.logWriter = logWriter; 74 this.synchronizer = synchronizer; 75 } 76 run()77 public void run() { 78 79 synchronized(OwnedMonitorsDebuggee.waitForFinish){ 80 81 synchronized(OwnedMonitorsDebuggee.waitForStart){ 82 83 OwnedMonitorsDebuggee.waitForStart.notifyAll(); 84 85 logWriter.println(getName() + ": started"); 86 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 87 88 logWriter.println(getName() + ": wait for SGNL_CONTINUE"); 89 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 90 logWriter.println(getName() + ": finished"); 91 } 92 } 93 } 94 } 95 main(String [] args)96 public static void main(String [] args) { 97 runDebuggee(OwnedMonitorsDebuggee.class); 98 } 99 } 100