Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes Accessing pre-generated identifiers from a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing pre-generated identifiers from a Servlet" Watch "Accessing pre-generated identifiers from a Servlet" New topic

Accessing pre-generated identifiers from a Servlet

Ujjwal K Gaurav

Joined: Jun 02, 2012
Posts: 1
For my web application, I am expecting a peak load of about 1000 concurrent requests per second for a period of 5-10 minutes every business hour of the day. My web application needs to generate a 9 digit unique hexadecimal number, and send it as a response and also persist the same in the database.

As a solution, I am trying to pre-generate a Set of 5000 identifiers and keep it ready. During the peak load, I want my Servlet to simply keep popping out the generated the identifiers and use them in responses. When the generated Set count falls below 2500, I want to regenerate another 2500 unique identifiers and populate the same Set and keep it ready again.

Can someone please suggest a way to implement this?

Thanks in advance.
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

Welcome to the Ranch!

If you persist it in a database anyway, I'd suggest to use a database mechanism for generating the IDs, such as a sequence or an autogenerated ID. You wouldn't finish handling the request till it's committed anyway, would you?

(I'm not sure about other databases, but Oracle's sequences can actually be configured to cache values exactly in the way you're describing. They are pretty fast.)
I agree. Here's the link:
subject: Accessing pre-generated identifiers from a Servlet
It's not a secret anymore!