2) Consider a class DEF where a static field is being accessed by a non-static synchronized method. We create 2 instances of the class - DEF_01 and DEF_02. Now, thread B is accessing the non-static method of DEF_01 and hence has obtained a lock on DEF_01, and another thread C is accessing non-static method of DEF_02 and so has obtained a lock on DEF_02. However, the method is trying to change the value of same static variable. What will happen in such case?
Since the data being accessed is shared (by virtue of being static) but the locks being used is not (because the two threads are synchronized using different objects) the data is unprotected, and problems can arise.
fred rosenberger wrote:you can use the javap command to read the class file:
C:\slop>javap Dog.class
Compiled from "Dog.java"
public class Dog extends Animal {
Dog();
}
C:\slop>javap Animal.class
Compiled from "Dog.java"
class Animal {
Animal();
}
C:\slop>