diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-02-23 14:13:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-02-23 14:13:04 +0000 |
commit | 92b03ef02b1a217397b4f2223c991114b644ac0f (patch) | |
tree | 6cf80bb4f9fed6caba29225765970e5adf74f157 | |
parent | abb611dcc070b5aab2ace7a30c63b78de05df7ed (diff) | |
parent | ff05d9d01cb458e145c4788ae8b979deb77c3421 (diff) | |
download | apache-harmony-92b03ef02b1a217397b4f2223c991114b644ac0f.tar.gz |
Merge "Wait for helper thread to finish in MonitorContendedEntered test" into main
-rw-r--r-- | jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java index de5b397..53708d4 100644 --- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java +++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/Events/MonitorContendedEnterAndEnteredDebuggee.java @@ -50,13 +50,27 @@ public class MonitorContendedEnterAndEnteredDebuggee extends SyncDebuggee { Thread.yield(); logWriter.println("main thread: Waiting for second thread to attempt to lock a monitor"); } - + // We think the monitor is contended. synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); // Make sure we're good to finish. synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); logWriter.println("--> main thread: finish test"); } + + // Wait for the blocked thread to join. This makes sure we entered the synchronized section + // in the blocked thread and hence the MonitorContentedEntered message should be sent. If we + // don't wait here, there is a possibility we exit the process before the blocked thread + // gets a chance to enter the monitor lock. + boolean done = false; + while (!done) { + try { + thread.join(); + done = true; + } catch(InterruptedException e) { + System.out.println("Thread interrupted when joining, giving another chance"); + } + } } static class BlockedThread extends Thread { |