• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Necessity of cookie

 
Marcio Aun Migueis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

This is my update method, from URLyBird version 1.2.3



I don�t understand the necessity of lockCookie. Because, before execute
the update, my code first lock the record. And I�m sure that I only can
have one lock per room per client.

My code book a room in three separated steps:

1) lock the record
2) update the record
3) unlock the record

The follow example show two clients trying to book the same room.

1) Client A lock record 45
2) Client B try to lock the same record, but he has to wait until A unloncks it.
3) Client A update the record ( book the room )
4) Client A releases the lock ( and notify all )
5) Client B acquire the lock
6) Client B has to check if the room is available
7) Client B receive a message, because the room is booked by another one.
8) Client B releases the lock

If a room could only be locked by one client at time, why do I need to verify is this room is locked by another client ? Do I have to change my design choices ? Do I have to lock the record inside the update method ?

Thanks in advance ( and sorry my poor English ).

M�rcio
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi M�rcio,

Welcome to JavaRanch and this forum.

You stated that: "before execute the update, my code first lock the record. And I�m sure that I only can have one lock per room per client." (my highlighting). Some potential problems with that could be if
  • the junior programmer assumes that as long as they have any lock they can modify any record (if the record is not tied to the cookie, then you could lock record 5 and modify record 7)
  • based on the previous point, the junior programmer decides to remove the calls to the lock and unlock methods
  • a business decision is made that more than one room should be lockable by one client at any given time
  • the application is split into multiple tiers on different computers (a web tier, a business tier, and a database tier) - you now have to worry about how you identify which client from the business tier locked the record
  • Does having (and using) the cookies solve these problems for you?

    Having said all that, I agree that cookies are fairly useless - you can solve these problems without cookies (and the forum members who currently have assignments without cookies have to solve them). If Jim Yingst was still in this forum he would be most vocal about how useless cookies are . But you do have them, so why not use them?

    Regards, Andrew
     
    Marcio Aun Migueis
    Ranch Hand
    Posts: 32
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Andrew,

    I thought the cookies were unnecessary, but I have to use them. I don�t fell confortable with them, but I can change my mind about it.

    I have to think that my implementatios are real software, where I have to take care about how others programers would work whit it.

    Thanks ( and waiting your book ),

    M�rcio
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic