Code Example: Scheduler continued
// If resource is not busy, synchronize on this
// ensuring 2 calls don’t both return immediately.
synchronized (this) {
if (runningThread == null) {
runningThread = thisThread;
return;
} // if
waitingThreads.add(thisThread);
waitingRequests.add(s);
} // synchronized (this)