Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets & global stateful in-memory objects

 
Keith Tingle
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic