Here an arrow from action A to action B indicates that A must precede B . Also, even though method to is synchronized , method fro is not synchronized , so there is nothing to prevent the read actions from occurring between the lock and unlock actions. As a result, the method fro could still obtain either 1 or 3 for the value of a , and independently could obtain either 2 or 4 for the value of b . In particular, fro might observe the value 1 for a and 4 for b . Creating a Thread object creates a thread and that is the only way to create a thread.
Every thread has a priority .
When there is competition for processing resources, threads with higher priority are generally executed in preference to threads with lower priority. Such preference is not, however, a guarantee that the highest priority thread will always be running, and thread priorities cannot be used to reliably implement mutual exclusion. There is a lock associated with every object. After the lock action has been performed, the body of the synchronized statement is executed. If execution of the body is ever completed, either normally or abruptly, an unlock action is automatically performed on that same lock.