• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synhronization

 
Mathew Sam
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the LockManager class i have only two synchronized methods.Do I need to sychronize the access to the HashMap like
synchronized(locks) { }
class LockManager {
private HashMap locks = new HashMap();
pubilc synchronized void lock (){
// Access HashMap
}
pubilc synchronized void unlock (){
// Access HashMap
}
}
 
mike seluker
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mathew Sam:
In the LockManager class i have only two synchronized methods.Do I need to sychronize the access to the HashMap like
synchronized(locks) { }
class LockManager {
private HashMap locks = new HashMap();
pubilc synchronized void lock (){
// Access HashMap
}
pubilc synchronized void unlock (){
// Access HashMap
}
}

You don't have to synchronized on hashmap if u r synchronizing on methods. You synchronize on either methods or hashmap but avoid on both.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!