You can wait for an object that no one will notify ...
synchronized (someObjectNobodyWillNotify) { try { someObjectNobodyWillNotify.wait(0, nanosToSleep); } catch (InterruptedException e) { Thread.interrupt(); } }
(In this case, I assume that the false awakenings are in order. If not, you need to write your System.nanoTime() at the beginning and wrap the wait in a loop that checks that enough time has passed.)
yshavit
source share