This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Queuing requests

 
Greenhorn
Posts: 18
  • 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
 
Ranch Hand
Posts: 83
Hibernate Spring Java
  • 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.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • 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

 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic