You would be still synchronized to the old processStatusCode. If then,
you were to wait like here :
synchronized(processStatusCode){
if (processStatusCode == JUST_STARTING){
//do something
processStatusCode = GETTING_ALONG_NOW;
try {
processStatusCode.wait(100); // <<-- here
} catch (Exception e) {
e.printStackTrace();
}
} else if (processStatusCode == GETTING_ALONG_NOW){
//do something else
processStatusCode = DONE_BY_GOSH;
}
}
you would get a java.lang.IllegalMonitorStateException.
Even if you didn't have to wait, other threads would not be able to know
what clock to acquire while competing for the critical resource.
Andi Mullaraj
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
> Behalf Of Richard O. Hammer
> Sent: Friday, February 13, 2004 9:51 AM
> To: Java Users Group
> Subject: [Juglist] synchronization on reassigned field
>
> I've written code something like this:
>
>
> final static String //process status codes
> JUST_STARTING = "just starting",
> GETTING_ALONG_NOW = "going okay",
> DONE_BY_GOSH = "all wrapped up";
>
> String processStatusCode = JUST_STARTING;
>
> ...
>
> synchronized(processStatusCode){
> if (processStatusCode == JUST_STARTING){
> //do something
> processStatusCode = GETTING_ALONG_NOW;
> }else if (processStatusCode == GETTING_ALONG_NOW){
> //do something else
> processStatusCode = DONE_BY_GOSH;
> }
> }
>
> I think maybe I'm getting myself into trouble here, but I'm not quite
> sure. If I get a lock on the object assigned to processStatusCode and
> then reassign processStatusCode to point to a different object, where
> does my synchronization stand?
>
> Thanks,
> Rich Hammer
>
>
> _______________________________________________
> Juglist mailing list
> [EMAIL PROTECTED]
> http://trijug.org/mailman/listinfo/juglist_trijug.org
>
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org