| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
How to use the synchronized keyword?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
How to use the synchronized keyword?There are two syntactic forms based on the synchronized keyword, methods and blocks. A synchronized method acquires a lock before it executes. For example, the following synchronized method
class MyClass {
public synchronized void function() {
....
}
}
is equivalent to the following synchronized block
class MyClass {
public void function() {
synchronized(this) {
....
}
}
}
Few notes about synchronized keyword:
ReferenceConcurrent Programming in Java : Design principles and patterns by Doug Lea |