• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking Details

 
Jason Rosenblum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've implemented my locking strategy but I still have on unresolved issue. The locking is controlled by a LockManager class that has a Map of locked records. When I update this Map (lock or unlock) does the operation need to be atomic (do i need to synchronize it)? If so, what would I synchronize on, the instance of Data or the Map instance?
My initial assumption is that i do not need to synchronize this operation because I would like multiple threads to concurrently be able to update the LockManager. Two threads requesting to lock two different records would run at the same time. In the case of two threads trying to update the same record, one thread would win and the other would wait. Can anyone offer some feedback? It would be greatly appreciated.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this lockManager is for all the clients, which it should be, yes you do have to synchronize, and the best is on the Map.
Like

synchronize or synchronized? I can't remember of the top of my head.
Mark
 
Jason Rosenblum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if my Map is static won't that lock the entire LockManager class preventing any updates to the Map? Feel free not to answer if i'm digging too deep into the details...
thank you,
~Jason
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is your Map static? Oh, unless the method is static too, then there never needs to be an instance of LockManager create.
I didn't have a LockManager in my submission, so I don't know the exact method of using it. I can see the advantages of it being static. Hmm, explain a little more about the LockManager, who uses it, where, and how? thanks.
Mark
 
Jason Rosenblum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just my stupid brain again...
LockManager should definitely NOT be static. I had implemented it as a utility class and I made everything static. This was obviously a mistake -- thanks for your help Mark.
~Jason
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic