November 2006
Intermediate to advanced
224 pages
3h 29m
English
public synchronized void myMethod() { // do something } |
You perform synchronization when you want to protect sections of code from being accessed by more than one thread at a time. The synchronized keyword, which we show in this phrase, allows us to synchronize a method or code block so that only one thread at a time can execute this method or code block. In this phrase, if one thread is currently executing myMethod(), any other threads attempting to execute the same method, myMethod(), on the same object instance will be locked out of the method until the current thread completes execution and returns from myMethod().
For non-static methods, the synchronization applies only to the object instance that another thread is ...
Read now
Unlock full access