While you should always try to avoid nested synchronization, sometimes it is not possible to avoid it totally. As long as you always nest in the same order you should be OK.
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Are you finished with the SCJD cert?
Did you use the synch mechanism that you described in that post? Or did you do some last modifications?
- Did you synch on dbFile when changing database file as well?
- I don't see that it is possible for two threads to read two different records?
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
SCJD<br />SCJP 1.4
In your unlock method, is the first check of recNo in recValidFlags necessary? You have to check after getting the record lock anyway, so the first check one seems like extra work.
I believe using notifyAll() violates the requirement that a Thread must consume no CPU cycles...
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Originally posted by Alex Sharkoff:
but notify does not guarantee that a particular thread will ever be notified. So I think it's fairer to allow all waiting threads to get back into the ready state, compete for the monitor and go into waiting state again if required.
Kind regards.
You are correct in that notify() does not guarantee a particular thread will be notified. However, it does guarantee that a thread will be notified, provided that one is waiting for the lock
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Whether you call notify() or notifyAll(), only one thread gets the lock. It doesn't matter if they wake up or not, only one thread is going to get it. The only way a thread won't get notified is if the owner of the lock doesn't call notify()
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation.
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Originally posted by Alex Sharkoff:
Kevin,
Imagine, if you've got threads coming in all the time and jumping on the waiting list. If we notify then Thread Scheduler might keep notifying the very last thread that jumped on the waiting list.
[ February 07, 2006: Message edited by: Alex Sharkoff ]
SCJD<br />SCJP 1.4
SCJD<br />SCJP 1.4
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Acetylsalicylic acid is aspirin. This could be handy too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|