< prev index next >
test/hotspot/jtreg/runtime/handshake/HandshakeDirectTest.java
Print this page
@@ -22,11 +22,11 @@
*
*/
/*
* @test HandshakeDirectTest
- * @summary This test tries to stress direct handshakes between threads.
+ * @summary This test tries to stress direct handshakes between threads while suspending them.
* @library /testlibrary /test/lib
* @build HandshakeDirectTest
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+SafepointALot -XX:BiasedLockingDecayTime=100000000 -XX:BiasedLockingBulkRebiasThreshold=1000000 -XX:BiasedLockingBulkRevokeThreshold=1000000 HandshakeDirectTest
*/
@@ -101,9 +101,30 @@
workingThreads[i] = new Thread(test, Integer.toString(i));
workingThreads[i].setDaemon(true);
workingThreads[i].start();
}
+ // Fire-up suspend-resume thread
+ Thread suspendResumeThread = new Thread() {
+ @Override
+ public void run() {
+ while (true) {
+ int i = ThreadLocalRandom.current().nextInt(0, WORKING_THREADS-1);
+ workingThreads[i].suspend();
+ try {
+ Thread.sleep(1); // sleep for 1 ms
+ } catch(InterruptedException ie) {
+ }
+ workingThreads[i].resume();
+ }
+ }
+ };
+ suspendResumeThread.setDaemon(true);
+ suspendResumeThread.start();
+
// Wait until the desired number of direct handshakes is reached
- workingThreads[0].join();
+ // and check that all workers exited
+ for (int i = 0; i < WORKING_THREADS; i++) {
+ workingThreads[i].join();
+ }
}
}
< prev index next >