Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto Generation of Sequence Numbers  RSS feed

 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is similar to generating ID number for each record in database; however, it is to generate a sequence number for every client request received over the web.

I heard that there are 1. idempotent sequence number, which has to be thread safe, and 2. global sequence number.

Are there code examples that I can follow? Thank you.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For unique random ids you can use java.util.UUID : randomUUID()
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to use the java.util.concurrent.atomic.AtomicInteger in a Singleton?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be like writing any other Singleton class


 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for your help and support.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!