File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question related to synchronization

 
Gaurav Chhabras
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
tanu dua
Ranch Hand
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Gaurav

Synchonization - threads

Study this link.........it tells more than u expected
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic