raja singh kumar wrote:. . . . Lock is acquired for which object?
Look in the
Java® Language Specification. It tells you which object is used as the monitor.
If I remember correctly, a synchronised method is equivalent to wrapping the whole content of the method in
synchronized (this) { ... }
Also when a thread is executing the increment method can a second thread invoke the decrement method? . . .
That is the whole point of the synchronisation: stop a second thread accessing decrement() until increment() has completed and the lock has been released. I presume the get method was only there to show how the examplle works. Please work out whether you really need that get method to be synchronised.