A thread acquiring the lock of a class to execute a static synchronized method,has no bearing on any thread acquiring the lock on any object of the class to execute a synchronized instance method.
Hi Anil,
class DemoThread extends Thread{
public void run() {
}
public synchronized static void doStuff1() { //Lock of the class
}
public void doStuff2() {
synchronized(this) { //Lock of the instance of the class
....
}
}
public static void main(
String... args) {
}
}
Inside the static method, there is no "this". So a thread acquiring lock on the static method has no bearing of the lock of the syncrhonized instance method. So while a thread executing a static synchronized method,
it has no bearing on any thread acquiring the lock on any object of the class to execute a synchronized instance method.
Got it?
Thanks and Regards,
cmbhatt
[ March 31, 2007: Message edited by: Chandra Bhatt ]