summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Hao <jeffhao@google.com> 2016-06-15 16:20:34 -0700
committer Jeff Hao <jeffhao@google.com> 2016-06-15 17:29:05 -0700
commitab820ee8f8f7201383ec78ae11f50d6b234cd1ce (patch)
tree7d3efb40a7df49dd919c4f27a899a078fda59872
parentabdda2fb52eb7e9a6916899a913f78251d8ed277 (diff)
Use a barrier instead of sleep for flaky deadlock test.
Bug: 28663029 Change-Id: Ia94372c719f8014b4ee739ebc6a93c4f3548f717
-rw-r--r--test/033-class-init-deadlock/expected.txt2
-rw-r--r--test/033-class-init-deadlock/src/Main.java13
2 files changed, 7 insertions, 8 deletions
diff --git a/test/033-class-init-deadlock/expected.txt b/test/033-class-init-deadlock/expected.txt
index 182d0da00d..9e843a06f6 100644
--- a/test/033-class-init-deadlock/expected.txt
+++ b/test/033-class-init-deadlock/expected.txt
@@ -1,6 +1,4 @@
Deadlock test starting.
-A initializing...
-B initializing...
Deadlock test interrupting threads.
Deadlock test main thread bailing.
A initialized: false
diff --git a/test/033-class-init-deadlock/src/Main.java b/test/033-class-init-deadlock/src/Main.java
index 32332307f5..3346aa6813 100644
--- a/test/033-class-init-deadlock/src/Main.java
+++ b/test/033-class-init-deadlock/src/Main.java
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+import java.util.concurrent.CyclicBarrier;
+
/**
* This causes most VMs to lock up.
*
@@ -23,6 +25,8 @@ public class Main {
public static boolean aInitialized = false;
public static boolean bInitialized = false;
+ public static CyclicBarrier barrier = new CyclicBarrier(3);
+
static public void main(String[] args) {
Thread thread1, thread2;
@@ -30,10 +34,9 @@ public class Main {
thread1 = new Thread() { public void run() { new A(); } };
thread2 = new Thread() { public void run() { new B(); } };
thread1.start();
- // Give thread1 a chance to start before starting thread2.
- try { Thread.sleep(1000); } catch (InterruptedException ie) { }
thread2.start();
+ try { barrier.await(); } catch (Exception e) { }
try { Thread.sleep(6000); } catch (InterruptedException ie) { }
System.out.println("Deadlock test interrupting threads.");
@@ -48,8 +51,7 @@ public class Main {
class A {
static {
- System.out.println("A initializing...");
- try { Thread.sleep(3000); } catch (InterruptedException ie) { }
+ try { Main.barrier.await(); } catch (Exception e) { }
new B();
System.out.println("A initialized");
Main.aInitialized = true;
@@ -58,8 +60,7 @@ class A {
class B {
static {
- System.out.println("B initializing...");
- try { Thread.sleep(3000); } catch (InterruptedException ie) { }
+ try { Main.barrier.await(); } catch (Exception e) { }
new A();
System.out.println("B initialized");
Main.bInitialized = true;