Java Reference
In-Depth Information
Synchronization forces execution of the two threads to be mutually ex-
clusive in time. Unsynchronized access does not wait for any locks but
proceeds regardless of locks that may be held on the object.
Locks are owned per thread, so invoking a synchronized method from
within another method synchronized on the same object will proceed
without blocking, releasing the lock only when the outermost synchron-
ized method returns. This per-thread behavior prevents a thread from
blocking on a lock it already has, and permits recursive method invoc-
ations and invocations of inherited methods, which themselves may be
synchronized.
The lock is released as soon as the synchronized method termin-
ateswhether normally, with a return statement or by reaching the end of
the method body, or abnormally by throwing an exception. In contrast
to systems in which locks must be explicitly acquired and released, this
synchronization scheme makes it impossible to forget to release a lock.
 
Search WWH ::




Custom Search