Questions about timing within synchronized blocks
From: Robert Mark Bram (none)
Date: 05/31/04
- Next message: Andrew Thompson: "Re: OT: Speaking in Tongues"
- Previous message: Michiel Konstapel: "Re: getting jar file's place"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 1 Jun 2004 02:50:58 +1000
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
:)
- Next message: Andrew Thompson: "Re: OT: Speaking in Tongues"
- Previous message: Michiel Konstapel: "Re: getting jar file's place"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|