Hi all,
Having noticed a deadlock in my code I have went through this forum reading for suggestions on locking.
However, there seems to be a discussion about using notify of notifyAll in combination with a wait on some locked object.
Everyone is concerned about the requirement that no CPU cycles should be consumed when attempting to lock some record that is already locked.
If you use the wait method to do this waiting for the unlock of the record you can never guarantee that no CPU cycles are consumed.
I quote from
Java's documentation of the wait method:
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop.
So, since these spurious wakeups can occur we can never ever guarantee that no CPU cycles are used when we use the wait method.
Any comments on this, I might be far off.
How would we do the locking without using wait/notifyAll/notify ?