This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Some lock doubts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Some lock doubts" Watch "Some lock doubts" New topic
Author

Some lock doubts

Marcio Aun Migueis
Ranch Hand

Joined: Sep 15, 2003
Posts: 32
Hi ,

I�m using the following map to manage my locked records


The key value is the record number, and the contents is the cookie. Is this approach correct ? May I use the Java 5 generics to define my map ?

My lock method is

Supose we have two clients trying to lock the same record. Before the put command, Client A put his cookie in the map. After that, client B put his own cookie. How to avoid this situation ? Do we have to synchronize the whole method ? Inserting synchronized to my method signature, Am I changing my interface specifications ?

Thanks in advance,

M�rcio
[ September 24, 2005: Message edited by: Marcio Aun Migueis ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi M�rcio,
May I use the Java 5 generics to define my map ?
Yes, you certainly can, and it is a good idea to do so.
Supose we have two clients trying to lock the same record. Before the put command, Client A put his cookie in the map. After that, client B put his own cookie. How to avoid this situation ? Do we have to synchronize the whole method ? Inserting synchronized to my method signature, Am I changing my interface specifications ?
According to the JLS "an interface may be implemented by a method that is declared strictfp or native or synchronized in a class that implements the interface."

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Marcio Aun Migueis
Ranch Hand

Joined: Sep 15, 2003
Posts: 32
Andrew,

Thanks a lot. you really help me.


M�rcio
[ September 26, 2005: Message edited by: Marcio Aun Migueis ]
 
 
subject: Some lock doubts
 
Similar Threads
Lock Cookie
SCJD failed, help needed with locking!
B&S: Why lock and update/delete throw RecordNotFoundException?
DeadLock
I passed, but I suffered the 44/80 locking penalty. Why?