• 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

servlet with a worker thread

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All

I don't know whether to post this here or in the multi-threading section so I'm starting here
I have a servlet that is the backend for a site where people enter zipcodes as part of some data they're entering
this data goes in a database
for each zipcode I want to go to one of the weather sites (weather.com) and download a lot of weather data for that zipcode
it's a time consuming process so in my init() function I set up a Timer which periodically fires off a thread to go do this background work
when I run the servlet in a debugger (I'm using Netbeans) everything works fine, but when I stop debugging the servlet the worker thread keeps running
so, I guess my question is this

if you have a servlet that requires a bunch of "house cleaning" chores (getting weather data) to be done periodically, what's the best way to achieve this?

Dave
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
init() is definitely not the right place for this kind of work. You can go like, your handler spin a new thread and forward the original request back to the user and show up some "in progress ... " kind of page. Meanwhile your browser will keep looking whether its done and ready or not after every given time. Then show the response page to the user when done.

You can search the same forum with the words "in progress", "show progress", "progress bar" and alike.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make the thread as deamon by using the following , in that case as soon as the main thread exits , your background thread would also die and will solve your issue.

 
reply
    Bookmark Topic Watch Topic
  • New Topic