Betamoo
Betamoo

Reputation: 15880

An always-running thread in Servelts

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??

Upvotes: 0

Views: 451

Answers (2)

Bruno Grieder
Bruno Grieder

Reputation: 29824

Other options in addition to the ones proposed by Morritz

  1. Inside Tomcat: register a global object accessible by all servlets using the Global JNDI
  2. Within the same JVM: start you shared resources (your static class, repository, etc...) and Tomcat programmatically (embedded) using a launcher like The Java Service Wrapper. You will need to define a small API implemented by your shared resource and usable by your servlets.
  3. Distributed accross JVM: memcached, hazelcast, etc...

Upvotes: 0

Moritz Petersen
Moritz Petersen

Reputation: 13057

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.

Upvotes: 3

Related Questions