synchronized statement acquires a mutual-exclusion lock (§17.1) on behalf of the executing thread, executes a block, then releases the lock. While the executing thread owns the lock, no other thread may acquire the lock.
synchronized ( Expression
The type of Expression must be a reference type, or a compile-time error occurs.
synchronized statement is executed by first evaluating the Expression. Then:
• If evaluation of the Expression completes abruptly for some reason, then the
synchronized statement completes abruptly for the same reason.
• Otherwise, if the value of the Expression is
NullPointerException is thrown.
• Otherwise, let the non-
null value of the Expression ...