Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Servlet container scope variable

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a solution for creating property variables that are container-scoped (available to all web-applications). I'm sure there is but I can't seem to find any docs for this. Can these properties be db driven in any way?

Thanks
 
Bartender
Posts: 20827
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not supported in the J2EE or JEE standards. The widest property scope that the standards address is Application Scope.

Effectively, each webapp in a J(2)EE container is the only webapp in the JVM. Each webapp has its own individual classpath, so sharing static class properties between webapps can be problematical, especially considering that some of the JVM implementors have been experimenting with things that may raise that wall even higher.

There are some tricks that can be used. For example, shared sessions, although they are per-user cross-application objects. You can create shared class libraries and place them in the TOMCAT_HOME/lib directory, but it will be up to you to provide your own access methods and thread-safe access. Both of these tricks require not only stepping outside of the standards, but also special configuration of the webapp server itself.

A more standardized approach would be to implement shared objects as EJBs. Although Tomcat itself does not implement EJBs, there are ways to get around that. EJBs were originally specifically designed to allow applications to share data not only across applications, but also across JVMs. The original mechanisms were fairly cumbersome, but EJB3 has simplified things a lot.

While working with EJBs isn't quite as simple as working with property sets, you could front a set of EJBs with a Property manager. It wouldn't be quite the same as the standard scope sets, but it would be close enough for comfort, I think.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!