• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

asynchronous processing in a servlet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:

I have an application running in an OC4J application server. My JSP calls into an action servlet to perform a particular task and then redirects to a results JSP.

The issue I have is that the task to be done is very long and I would like to start it asynchronously from the servlet and have the results JSP retrieve data as it becomes available.

Not being particularly experienced with servlets, my main idea is to make a JMS call to start my async task and then I can redirect to my results page and wait for data.

I'm wondering if anyone has ideas on other ways to do this that may be better.

Jon
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's how I handle long running processes.
The status page refreshes every n seconds.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there,

I had to do the same thing a couple of projects ago. What I adopted was the "Orbitz" model. In my case we were not using JMS but manually handling it via java threading. Here are the steps:

1. Process initial request
2. Spawn thread to do long task
3. Forward user to page with flashing/filling/rotating 'processing' image.
4. 'Processing' page has javascript function to ping the server every 2 seconds to see in the thread has finished. If it is unfinished it continues to flash.
5. Eventually the thread completes processing and sets a flag on a servlet/EJB.
6. The 'Processing' page then sees the data is ready and the servlet forwards the request to a results page.

I hope that helps.

Tom
 
Jon Wynett
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Those ideas seem to confirm what I was thinking.
 
Ranch Hand
Posts: 120
IntelliJ IDE Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have database it could be also possible to have some table that stores "jobs list". So once your servlet is called it generate job id and put new record in the list of not processed jobs. Then it returns to user information about job id and probably the time when user should expect job completed (it could be determined as avarage processing time multiplied by number of unprocessed jobs). Then another task that works in batch mode will process this job and set some mark. Using this approach you will have two level operation that probably looks more similar how such kind of operations are performed in the real life.
 
The only cure for that is hours of television radiation. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic