// In Java, all instances of Object are also a monitor.
// See https://en.wikipedia.org/wiki/Monitor_%28synchronization%29
Foo myMonitor = new Foo()
// To "enter" a monitor, you use 'synchronized'.
synchronized (myMonitor) {
// Inside the monitor, we could do a Thread.sleep.
Thread.sleep(100);
}
This is a very simplistic problem case. However, it is very possible for this to become a bigger problem. Because I can call arbitrary code when "inside" a monitor, it is very possible to call a method that does a sleep incidentally. (e.g. many implementations of IO operations will require some sort of sleep.)
[1] Something akin to https://www.evernote.com/shard/s9/res/11fab8e3-d623-4b58-a8d.... I'm sure there are libraries out that that will do this for you, but the algorithm in that paper isn't too hard to implement. :)