wood burning stoves
The moose likes Servlets and the fly likes Request prioritization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request prioritization" Watch "Request prioritization" New topic

Request prioritization

Aditi Gandy
Ranch Hand

Joined: Apr 23, 2008
Posts: 37
Hi all,
Can any one tell me how to prioritize the requests in service method?
Assuming that there are thousands of requests coming to the servlet at the same time, how to prioritize which request to be considered first?

Thanks & Regards,
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You have not control over the threading behaviour of the servlet container so there isn't much you can do. Sounds like an odd requirement though, why do you need to prioritize one specific client?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
Like Paul mentions it is indeed a strange requirement.
But then if you *really* need to implement something like that you can probably queue up the requests in a synchronised list, and have an independent thread scan this list and pick up requests to service based upon some 'priority' parameter value.

On the flipside, like you mentioned there may be thousands of requests - I really won't suggest using a data-structure to queue up the requests [you never know when your JVM runs out of memory]. Also, I'm pretty sure that the end user [client] experience won't be that great. Especially so, when the server makes him/her wait for a response for no apparent reason [assuming they aren't aware of the prioritisation of requests scenario]
Aditi Gandy
Ranch Hand

Joined: Apr 23, 2008
Posts: 37
Thank you Anirvan and Paul.

Thanks a lot.

This was asked in one of the interviews. I really didn't know the answer.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
While it's an unusual requirement, I don't think it's all that odd. There may be contractual QoS stipulations that offer higher priority for some clients (who would presumably have to pay for the privilege).
I agree. Here's the link: http://aspose.com/file-tools
subject: Request prioritization
jQuery in Action, 3rd edition