This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing pre-generated identifiers from a Servlet

 
Ujjwal K Gaurav
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic