synchronized |
keyword in metod declaration. |
Used to prevent simultanious access for object data members
and methods.
Same as synchronized( this ) inside of method.
|
class Foo { public syncronized void aMethod() { // ... } }
|
|
synchronized(obj) |
statement in block |
Lock access to object in scope of block
|
class Foo { Object sync=new Object(); void aMethod() { synchronized( sync ) { // ... } }
|
|
object.wait([milis[,nanos]])
|
methods in java.lang.Object
( parent for any object )
|
Stops current thread execution until notify()
or notifyAll() will be called by another thread.
|
class Foo { Object sync=new Object(); void aMethod() { // exception handler not shown synchronized( sync ) { sync.wait(); // ... } } }
|
|
object.notify()
object.notifyAll()
|
methods in java.lang.Object |
Release threads, waiting for notification.
|
class Foo { Object sync=new Object(); void aMethod() { synchronized( sync ) { // some locked processing.. sync.notifyAll(); } }
|
|
static initializators
|
static variable initialization or static block
|
Lock access to class-scope variables
|
class Foo { static Object gblSync=new Object(); // static initializator locks class static { // this block locks class ... } }
|
|