« Return to Thread: Recent change to ThreadWaitSleeper

Recent change to ThreadWaitSleeper

by tpeierls :: Rate this Message:

Reply to Author | View in Thread

Revision 1987 has the comment "fixing tomcat reverse ajax bug, which was a nasty synch issue."  I'm looking at the diff and I don't understand what the problem was before, nor how it was fixed.

I do see some problems, though. The boolean wakeUpCalled field should probably be declared volatile, since it is not accessed consistently with a particular lock held -- there is no "x" for which @GuardedBy("x") is true for that field.

The lock objects should be final; it's one less thing to reason about.

More importantly, this looks like something that could be achieved better and more maintainably with higher-level concurrency utilities. A CountDownLatch with intial count of 1, for example: latch.await() followed by runnable.run() for goToSleep(runnable); latch.countDown() for wakeUp().

--tim

 « Return to Thread: Recent change to ThreadWaitSleeper