• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

B&S: Simplest locking successful?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roberto, that's what I was looking for.

Thanks!

 
Is that a spider in your hair? Here, threaten it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic