[ebu]: __How can you share information between webapps?__

Ideally, we want something delineated by the [Servlet] API, 
not container specific. A brief web perusal indicated no
easy solution. (Someone suggested going to [J2EE] and [EJB|Enterprise JavaBeans]'s,
someone else noted that two webapps in Tomcat 3.2.1 sometimes
get object instances from the other app's JAR instead of the
different version in their own. (unconfirmed) Not very helpful.)

[Asser]: __Re: How can you share information between webapps?__

Yes, it is true that there can be different JAR files for different
applications, which obviously means that there can be different versions
of class files even. More detailed description about this problem
can be found from [A2AClassCastException]. Fortunately there are many
neat ways to solve this problem varying in their scalability and its
cost in terms of overhead.


You can use a special container to share objects within the same
[JVM] so that all appliations can refer to its content. It is important
that the handle to the container is unique and visible for all

The way communication works with a resource container is as follows.
Applications can send messages to each others using their own
mailboxes (resources with certain names) and __standard__ objects
like {{String}}s, {{Number}}s, etc... so that there won't be any
class instance variations among messages. The mailbox implementation
can be part of the resource container or you can use standard
objects like {{java.util.LinkedList}} if you have your own synchronization

Customized object types (classes from the applications) should be
constructed using resource container (for example [Regex] ResourceContainer
is using {{ResourceFactory}} classes for this) or then you should
use the same {{ClassLoader}} that was used for the container. You can
get the loader by calling {{container.getClass().getClassLoader()}}.


Yes, I know that sockets are heavy weight solution for the communication
between applications running in the same JVM but I think they deserve
to get mentioned anyway since they have some scalability advantages.
Applications with socket level communication layer are readily capable
to act in their decentralizated form in distributed systems.

Object streams (class serialization) can be used in most cases for the
actual communication.

The usage of localhost loop ( in IP environments might speed up
things a bit since it has been optimized in some protocol stacks.