| Author |
question related to synchronization
|
Gaurav Chhabras
Ranch Hand
Joined: Sep 21, 2005
Posts: 126
|
|
What does the line means -: synchronization of static methords in a class is independent from the synchronization of instance methords on object of the class. Please explain the meaning of the above line. Thanks Regards Gaurav
|
 |
Ashwin Kumar
Greenhorn
Joined: Oct 13, 2005
Posts: 27
|
|
This means that - If a thread T1 has obtained a lock on the object, then another thread T2 cannot access any of "synchronized non-static" methods of the object. But thread T2 can very well access "synchronized static" methods of the object. To restrict access to "synchronized static" methods, the thread T2 must obtain a lock on the "Class" object. Hope this is clear.
|
SCJP 1.4<br />SCBCD 5.0<br />SCWCD 1.4 (Preparing)
|
 |
tanu dua
Ranch Hand
Joined: Apr 05, 2004
Posts: 145
|
|
Synchronization means acquiring the lock.There are 2 types of locks in Java : 1) Static Lock or Synchronization 2) Object Lock or Sysnchronization The above statement means that to acquire the lock of a class is different than acquiring the lock of an object of the class.Locking an object does not automatically protect access to static fields of that object's class or any of its superclasses. Access to static fields is instead protected via synchronized static methods and blocks. Static synchronization employs the lock possessed by the Class object associated with the class the static methods are declared in. And i guess locking a Class object also doesn't mean to lock all the objects of the class ? Anyone in the forum, could u plz clarify this.
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
hi Gaurav Synchonization - threads Study this link.........it tells more than u expected
|
 |
 |
|
|
subject: question related to synchronization
|
|
|