• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what are the locking alternatives

 
joel smither
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the different possibilities for locking? I know I use synchronized methods to enusre no two threads try to update the same record at the same time...but what other choices exist?
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using 1.4, you have choices of either synchronizing entire methods, or synchronizing on specific objects.

If you are using 1.5, you have an additional option of the new concurrency package. In the locking section, there is a class called ReentrantLock and an interface called Condition. They are claimed to work better than wait(), notify() and synchronization, as they are specially designed so that the JVM spends less time scheduling threads and more time executing codes. This is the option I have opted for now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic