You seem to be mixing things.
Firstly
public synchronized void method() {
}
is equivalent, from a synchronization perspective, to:
public void method() {
synchronized (this) {
}
}
The pros / cons have already been mentioned and the various duplicates give more information.
Secondly,
synchronized(someObject) {
//some instructions
}
means that the instructions in the synchronized block can't be executed simultaneously by 2 threads because they need to acquire the monitor on someObject
to do so. (That assumes that someObject is a final reference that does not change).
In your case, someObject
happens to be this
.
Any code in your object that is not synchronized, can still be executed concurrently, even if the monitor on this
is held by a thread because it is running the synchronized block. In other words, synchronized(this)
does NOT "lock the whole object". It only prevents 2 threads from executing the synchronized block at the same time.
Finally, if you have two synchronized
methods (both using this
as a lock), if one thread (T1) acquires a lock on this
to execute one of those 2 methods, no other thread is allowed to execute any of the two methods, because they would need to acquire the lock on this
, which is already held by T1.
That situation can create contention in critical sections, in which case a more fine grained locking strategy must be used (for example, using multiple locks).