• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Servlets & global stateful in-memory objects

Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a web application that basically acts as a batch process starter.

I have long batch processes that I dispatch off to threads, the servlet call that kicks this process off returns after setting up the batch process and creating the 'worker' thread.

So long after the servlet has done its HTTP work, the worker thread the servlet created is running its little heart out processing the batch job.

I would like my users to be able to visit a JSP or servlet page and check on the thread, perhaps get a quick report on what record the batch is processing, maybe cancel the job if needed etc...

It occurs to me that the best way to this is some kind of in-memory hash table with an auto-generated key that I return to my users. If they want status, they ask for it with the key, I use the key to look up the Runnable object and query for status.

Where is the best place to keep this hash table? It basically needs to be a global object accessible by servlets and my worker thread alike (for clean up).

Is there a standard approach to this kind of global object? I assume JNDI and a servlet context is the normal place for this sort of thing, are there any drawbacks?
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ServletContext would be a logical place to store things like this.

It's available to all servlets (and thus JSPs) running in the web application.
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic