Search code examples
javajsptomcatservletsinter-process-communicat

An always-running thread in Servelts


  • I need to built a thread/process that is always running, and can be queried through other servelts and JSP pages...
  • This thread/process will be dealing with large files, so it will cache file blocks to reduce file accesses (plus some other processing)...
  • So, that thread/process will be loaded and waiting for any queries coming, to answer... as long as the server is running.

I though about making a static class common between all the servelt classes, but I found out that will not work (tomcat deals with each new servelt as a totally new program)

So what are the other options I can try??


Solution

  • I think you have two options:

    1. Use the ServletContext to access application-wide scope objects.
    2. Use a more sophisticated solution, such as ehcache to put your data in memory.