Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

NX: about lock cookie

 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My DBAccess interface have two lock concerning methods:

Because the lock/unlock is consided only in network mode, I think the lock and unlock methods should be only implemented in RemoteData class, the Data class should only have empty lock/unlock methods like a WindowAdapter, am I right? thus there is a question: what should the lockRecord return, 0?
In network mode, I want to use the combination of the time when the record is locked and the record number as the cookie, thus the cookie is unique.
Waiting for your comment
Regards,
Tom
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Damu,

Because the lock/unlock is consided only in network mode ...


Why is the lock/unlock only considered in network mode?
Or, why can't you use lock/unlock in standalone mode?
Regards, Andrew
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Andrew,
Thank you for your reply first, I think in standalone mode there is only one user use the computer at any time, so there is not multi thread problem, so the lock issue is unnecessary.
Regards,
Tom
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi damu,


In network mode, I want to use the combination of the time when the record is locked and the record number as the cookie, thus the cookie is unique.


System.currentTimeMillis() is not precise enough to make sure your cookie is unique. But, BTW your lock cookie does not need to be unique : just difficult to guess by a malicious coder. Think of Random.nextLong().


Because the lock/unlock is consided only in network mode, I think the lock and unlock methods should be only implemented in RemoteData class, the Data class should only have empty lock/unlock methods like a WindowAdapter, am I right? thus there is a question: what should the lockRecord return, 0?


I agree with Andrew. Your design will be simpler if you keep locking for local access.
Best,
Phil.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Philippe ,
Thank you for reply.
since you implement the lock/unlock in data class, will you use it in standalone mode? But I think it is unnecessary.
Regards,
Damu
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi damu,
You're right, it's "unnecessary", but IMO, if you do, the benefits are that it's simpler to implement and simpler to maintain, actually at no cost (if there are no other clients competing for locks, locks are granted immediately in any case).
Best,
Phil.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Philippe ,
Yes, I see, you are right, thank you
Regards,
Damu
 
Every plan is a little cooler if you have a blimp. And a tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic