/** *Testlockedbyplatformthread,virtualthreadtriestolock.
*/
@Test publicvoid testReentrantLock4() throws Exception {
ReentrantLock lock = new ReentrantLock(); var holdsLock = new AtomicBoolean();
Threadthread;
// thread acquires lock
lock.lock(); try { thread = Thread.ofVirtual().start(() -> {
lock.lock(); // should block
holdsLock.set(true);
LockSupport.park();
lock.unlock();
holdsLock.set(false);
}); // give time for virtual thread to block Thread.sleep(500);
assertFalse(holdsLock.get());
} finally {
lock.unlock();
}
// virtual thread should acquire lock, park, unpark, and then release lock while (!holdsLock.get()) { Thread.sleep(20);
}
LockSupport.unpark(thread); while (holdsLock.get()) { Thread.sleep(20);
} thread.join();
}
// virtual thread2 should acquire lock while (!holdsLock.get()) { Thread.sleep(20);
} // unpark virtual thread and it should release lock
LockSupport.unpark(thread2); while (holdsLock.get()) { Thread.sleep(20);
}
thread1.join();
thread2.join();
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-10-11)
¤
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.