• 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic