{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Synchronized Class Method

Synchronized Class Method - become an atomic section •...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Synchronized Class Method All the statements in the method become the atomic section (synchronized block) and the Class object is the lock. class class_name { static synchronized type method_name1() { statement block } static synchronized type method_name2() { statement block } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Synchronized Instance Method All the statements in the method are part of the atomic section (synchronized block) and the instance object (this) is the lock. class class_name { synchronized type method_name1() { statement block } synchronized type method_name2() { statement block }
Background image of page 2
Synchronized Statement All the statements inside the defined synchronized block
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: become an atomic section. • The object in the parenthesis is the lock. class class_name { type method_name() { synchronized (object) { statement block } } } • All synchronized statements that share the same object will be mutually exclusive. Condition Variables in Java • Inside a synchronized block that uses an “ object” as the lock , you can use – object.wait() • The caller will wait until another thread calls “notify” on the object – object.notifyAll() • Wake up all threads waiting for object.wait....
View Full Document

{[ snackBarMessage ]}