• Post Reply Bookmark Topic Watch Topic
  • New Topic

lock

 
eswar kumar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i create a lock on a class ?and what are the types of locks available?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only type of lock which is supported as a primitive in Java is a re-entrant mutual exclusion lock.
The basic locking mechanism looks like this:

For any given object instance, only one thread may be synchronized on it at a time. Before entering a synchronized block any thread memory caches will be flushed.
The following idioms can be expressed in terms of synchronized blocks:


For a more extensive selection of lock types, check out Doug Lea's util.concurrent package (or wait until Java 1.5).
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!