Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Some lock doubts

 
Marcio Aun Migueis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11907
207
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marcio Aun Migueis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,

Thanks a lot. you really help me.


M�rcio
[ September 26, 2005: Message edited by: Marcio Aun Migueis ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic