How to Create a Distributed Application
A distributed web application is an application that is capable of running in a cluster of web containers. It's not very difficult to create a distributable application, as long as you follow these rules:
- HttpSession can be moved across cluster nodes. You must store only serializable objects in HttpSession (most EJB-capable container allow EJB references as well).
- The application has a separate ServletContext instance on every cluster node. Any attributes that you set in the context are local to the node that set them.
- As each node runs a separate Java VM, static fields are not distributed and thus any values stored in them are local to the cluster node.
In practice, that means if your application needs to keep data longer than for handling the current request, it needs to store it either in the HttpSession or in a database shared by all cluster nodes.
In order to mark your web application as distributable, you must put an <distributable> element in your web.xml. The element is always empty, you only need to add the following line:
<distributable />

