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

Servlet container scope variable

 
David Sheltby
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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE 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