@Override publicvoid run() { // Tell main thread we have started.
startSyncObj.countDown(); try { // Wait for main thread to tell us to race to the exit.
exitSyncObj.await();
} catch (InterruptedException e) { thrownew RuntimeException("Unexpected: " + e);
}
}
int timeMax = 0; if (args.length == 0) {
timeMax = DEF_TIME_MAX;
} else { try {
timeMax = Integer.parseUnsignedInt(args[0]);
} catch (NumberFormatException nfe) {
System.err.println("'" + args[0] + "': invalid timeMax value.");
usage();
}
}
timeMax /= 2; // Split time between the two sub-tests.
test(timeMax);
// Fire-up deamon that just creates new threads. This generates contention on // Threads_lock while worker tries to exit, creating more places where target // can be seen as handshake safe. Thread threadCreator = newThread() {
@Override publicvoid run() { while (true) { Thread dummyThread = newThread(() -> {});
dummyThread.start(); try {
dummyThread.join();
} catch(InterruptedException ie) {
}
}
}
};
threadCreator.setDaemon(true);
threadCreator.start();
test(timeMax);
}
publicstaticvoid test(int timeMax) {
System.out.println("About to execute for " + timeMax + " seconds.");
long count = 0; long start_time = System.currentTimeMillis(); while (System.currentTimeMillis() < start_time + (timeMax * 1000)) {
count++;
int retCode;
SuspendAtExit thread = new SuspendAtExit(); thread.start(); try { // Wait for the worker thread to get going. thread.startSyncObj.await(); // Tell the worker thread to race to the exit and the // SuspendThread() calls will come in during thread exit. thread.exitSyncObj.countDown(); while (true) {
retCode = suspendThread(thread);
if (retCode == JVMTI_ERROR_THREAD_NOT_ALIVE) { // Done with SuspendThread() calls since // thread is not alive. break;
} elseif (retCode != 0) { thrownew RuntimeException("thread " + thread.getName()
+ ": suspendThread() " + "retCode=" + retCode + ": unexpected value.");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.