In a class with synchronized methods and synchronized blocks. Are the monitor objects that govern the synronized methods and synchronized blocks the same, assuming that
1) the synchronized block is locking on a object defined within the class OR
2) the synchronized block is locking on the class itself (this)
i.e. if I have a class that implements Runnable as follows
could I be sured that the two synchronized methods and the synchronized block are all mutually exclusive?
1) the synchronized block is locking on a object defined within the class OR
2) the synchronized block is locking on the class itself (this)
i.e. if I have a class that implements Runnable as follows
could I be sured that the two synchronized methods and the synchronized block are all mutually exclusive?
Code:
private Boolean on;
public synchronized void setOn()
{
on = new Boolean(true);
}
public synchronized void setOff()
{
on = new Boolean(false);
}
public void run()
{
synchronized (this)
{
if (on.booleanValue())
{
//do some processing
}
}
}