Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Types of Lock in java object

 
Pankaj Patro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

What are the types of lock in java(like Object level, Class level lock).
and how these are used in the application.
 
Vaibhav Chauhan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object level lock: this is the lock that any thread aquires over nonstatic synchronized method. Any thread can invoke the synchronized method for different object other than the object that has invoked the synchronized method.

Class level lock: this is the lock that any thread aquires over static synchronized method. No thread can invoke the synchronized method for any object until the first thread which is having the lock releases it.



We need not to worry about locks during coding, it is decided by compiler depending upon keyword static.

I know only two locks, if there is any other locks please respond with answer.


hope you got it.
 
Pankaj Patro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I have got some Idea...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic