R
Robert Mark Bram
Hi All!
I have some questions about timing with synchronization.. Which is better:
Object sync;
....
synchronized (sync){
// Do important stuff..
sync.notifyAll();
} // end synchronized
or this:
synchronized (sync){
// Do important stuff..
} // end synchronized
sync.notifyAll();
In the first example, is there any chance that the timing will stuff up and
when blocked threads get notified, Java still thinks control is in the
synchronized section?
If I do something like this:
synchronized (sync){
// Do important stuff..
sync.notifyAll();
// Do more important stuff..
} // end synchronized
Obviously this is deadlock making code.. but what if "Do more important
stuff" was just "i+=1".. could it still work then?
Thanks for any advice!
Rob
I have some questions about timing with synchronization.. Which is better:
Object sync;
....
synchronized (sync){
// Do important stuff..
sync.notifyAll();
} // end synchronized
or this:
synchronized (sync){
// Do important stuff..
} // end synchronized
sync.notifyAll();
In the first example, is there any chance that the timing will stuff up and
when blocked threads get notified, Java still thinks control is in the
synchronized section?
If I do something like this:
synchronized (sync){
// Do important stuff..
sync.notifyAll();
// Do more important stuff..
} // end synchronized
Obviously this is deadlock making code.. but what if "Do more important
stuff" was just "i+=1".. could it still work then?
Thanks for any advice!
Rob