publicclass SetNameAtExit extendsThread { privatefinalstaticint DEF_TIME_MAX = 30; // default max # secs to test privatefinalstatic String PROG_NAME = "SetNameAtExit";
public CountDownLatch exitSyncObj = new CountDownLatch(1); public CountDownLatch startSyncObj = new CountDownLatch(1);
@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);
}
}
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++;
SetNameAtExit thread = new SetNameAtExit(); 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 // Thread.setName() calls will come in during thread exit. thread.exitSyncObj.countDown(); long late_count = 0; while (true) { thread.setName("T" + count + "-" + late_count++);
if (!thread.isAlive()) { // Done with Thread.setName() calls since // thread is not alive. break;
}
}
} catch (InterruptedException e) { thrownew Error("Unexpected: " + e);
}
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.