aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: Simplest locking successful? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S: Simplest locking successful?" Watch "B&S: Simplest locking successful?" New topic
Author

B&S: Simplest locking successful?

Volker Abel
Greenhorn

Joined: Nov 07, 2008
Posts: 13
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

Joined: Nov 07, 2008
Posts: 13
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

Joined: Sep 13, 2007
Posts: 2419
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Volker Abel
Greenhorn

Joined: Nov 07, 2008
Posts: 13
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

Joined: Sep 13, 2007
Posts: 2419
    
    7

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

Joined: Dec 28, 2007
Posts: 2265
    
    3

I synchronized all methods in my implementation of the Data class and got 80/80 for locking...


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Volker Abel
Greenhorn

Joined: Nov 07, 2008
Posts: 13
Roberto, that's what I was looking for.

Thanks!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S: Simplest locking successful?