Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

locking issue

 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have the following problem. My instructions say, that I'm required to implement (among the others) a lock method, which can look like this.

// Locks a record so that it can only be updated or deleted by this client.
// bla bla bla...
public long lock(int recNo) { }

How is it possible to do it with this argument? I would like to add clientId as a second argument, but this will violate the contract. I implemented my service as a singleton, so I cannot have multiple instances for each client (this would be hard to maintain). How would you conform that requirement without making a spaghetti architecture?
 
Rudolph Jen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a clientId. Use synchronized/wait/notify instead. Java helps us to supply multiply threads. I am "very happy" that I don't have to handle additional clientId's; keep it simple

Hope that helped.

Best Regards,
R
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, good idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic