A JBoss Subscription helps you keep JBoss clusters production-ready

Clustering and Caching in JBoss POJO Web Applications

Clustering is a key technology to make enterprise Java applications scalable. In a clustered environment, you can simply add more application servers to handle more requests. A distributed cache is a key component in an application server cluster. It guarantees that the cluster is transparent to other external components, such as the HTTP server and the database backend, as if it is a single server. It also reduces round trips between application components and improve the overall performance. Depending on their functions, there are two types of caches in an application server.

  • Entity cache stores database objects (i.e., EJB 3.0 Entity Bean instances) and database query results. Since it caches commonly used database objects in-memory, it drastically reduces the round trips to the database server and improves the application performance. The distributed entity cache allows a database object to be seen by all servers in the cluster once it is created or retrieved by one node.
  • State cache stores the application state information. It helps to all the nodes in the cluster to maintain identical application state and hence makes the cluster transparent. For instance, the clustered state cache can store HTTP session objects so that all server nodes have access to the same user session data. The state cache can be used to cluster stateful session beans. It could also store any transient application information that do not need to be persisted into a database. We will see more examples on this later in this tour.

In the JBoss AS, the default clustering and caching solution is based on the JGroups and JBoss Cache frameworks. JBoss Cache supports a high performance, in-memory, transactional, and replicated cache for the cluster. Using JBoss Cache, it is easy to cluster database-driven EJB 3.0 web applications. The key topics covered in this guided tour include the database entity cache, HTTP session state replication cache, generic application state cache, and cluster-wide single sign-on.

This tutorial assumes that you already know how to setup a JBoss cluster for web applications. If you do not, please refer to the materials in the "Further Reading" section. This tutorial does not cover caching services for clustered stateful session beans or the TreeCacheAop service for complex object graph caching. For those topics, please also refer to the "Further Reading" section.

Start the Tour

Further readings and source code



Michael Yuan and Norman Richards


You can find more in-depth information about JBoss and related products from our books.