• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Queuing requests

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 83
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic