public class SynchronizedCounter {
private int c = 0;
public synchronized void increment() {
c++;
}
public synchronized void decrement() {
c--;
}
public synchronized int value() {
return c;
}
}
If there are two threads, each having the same instance of SynchronizedCounter, does this mean that if one thread is calling increment, the other can not call decrement. Is the above code equivalent to a synchronised object? i.e.
public void run(){
synchronised( objectReferenceSynchronisedCounter){
if(conditionToIncrement)
objectReference....Counter.increment();
else
objectReference....Counter.decrement();
}
}