File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Queuing requests

 
Robin Heard
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is the scenario I'm trying to achieve:

10 users use a java servlet to request data.
The data can only be retrieved by the server by running a script that generally take between 1-5 minutes.
What would be the best way to implement a queuing system so that when the first user sends a request the server goes ahead and starts the script. If during that time a second and third user issues a request they are queued in the order they came in as?

Are there any frameworks for this?

Thanks
 
jagrutkumar dalwadi
Ranch Hand
Posts: 83
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your question, i seems that if particular resource has accessed, queuing mechanism needs to be set.

Servlets runs in multi threading environment. Here thread means user asking for resource. Please refer single threaded behavior of servlet.

If your requirement is for only one resource, you can create ServletRequestListener class which will handle such users. It will call for each and every request coming from user.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I would do is implement a Producer-Consumer pattern. You can have a queue that holds requests. A background thread waits for requests to appear on the queue. When a requests come, it picks the first one from the queue and executes it. After execution is done it checks for more requests in the queue. More requests = pop the next one execute it. No more requests = go back to sleep. The servlet should simply put the request in the queue and return back a message to the user that says "Your request is in queue. It is the Nth request in the queue, and it will approximately take T minutes". Provide another servlet that will allow the user to check the status of their request

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic