wait() should always be used in a loop to protect from spurious wakeups (see the javadoc for Object.wait())