• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Simplest locking successful?

 
Volker Abel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am currently working on the B&S locking strategy.

There is a simplistic approach to just synchronize all read and write methods in the Data class (server side) and implement wait/notify in the lock/unlock methods (with a Map recordId -> cookie).

Can one really score 80/80 Points using this approach (assuming it is implemented correctly of course)? Sounds too good to be true. No fancy ReentrantReadWriteLock fuss needed?

Somehow this appears "too simple" to me. And it means that you practically have a database lock because no two threads can execute methods of the Data class simultaneously.

Regards
Volker
 
Volker Abel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

maybe it was not clear what I meant with "simplest locking mechanism".

Pseudocode:


Does anyone know about scoring 80/80 with this strategy?

VA
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing UB not B&S but I'm sure locking is locking. Synchronizing all methods may be the simplest but may NOT be the most effective. For me anyway, I use "critical section" and "read/write lock" design patterns for my Data class.
 
Volker Abel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang , thanks for your reply. I agree that locking all methods is not the most effective. In a "real world" project this is very important. Here, the goal is different: score 80/80.

Would you say that efficiency a "must" for the assignment?
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Efficiency isn't the most important. But do need to consider code clarity and maintainability and of course the overall design. Of course making it work and not hang (eg getting deadlock) is the key.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I synchronized all methods in my implementation of the Data class and got 80/80 for locking...
 
Volker Abel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto, that's what I was looking for.

Thanks!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic