• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

I know it has been beaten to death, but ...

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't find a post solving the uniqueness issues in generating two identical cookies for two clients.

Cannot you just use random() and before giving it to the client, check a Set to see if it is there?

I plan to do this in my assignment (changing from a sequential cookie scheme).

Does anyone see a potential problem in this?

Eva
 
Eva Van Shtock
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, how about this:
for a unique cookie, we return the file pointer (offset) pointing to the record we want to lock.

Eva
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Eva,

I saw an interesting posting which suggested using System.nanoTime() to generate a unique number. I guess you could go for some complex algortihm to try to generate a truly unique random number but i feel it probably just complicates things too much - better to keep it simple.

Robert
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just generate a serial number i.e.

private long id = 0;

synchronized long getNextID() {
return id++;
}
 
Ranch Hand
Posts: 284
Netbeans IDE Firefox Browser Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Eva,
you can't ensure cookie uniqueness since cookie domain is finite.
For long cookies after 2^64 + 1 cookies returned, is sure at least two of them are the same.
What you can do is trying to minimize cookie repetition, or better cookie repetition per record

Regards
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with min for a datatype and add one until you get max for a data type/ With that many values, requests literally cannot overlap - it would take a request to hang around for days if not months if not years. But this implies that your locking is good.
 
We can walk to school together. And we can both read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic