In this tutorial we will show how to achieve High Availability with your Enterprise Java Beans using a simple Stateful clustered EJB and a remote Client.

 Clustering stateful session beans requires JBoss AS to manage the state information. The component that is in charge to manage state information is Infinispan, which by default uses Replication to keep the session synchronized between components, each time the state of a bean changes.

In this tutorial we will set up and test a standalone cluster made up of two nodes and we will deploy our Stateful EJB on both nodes, by simply dropping the artifact on the deployments folder. Here's a picture of our cluster definition:

cluster jboss high availability ha tutorial cluster

Now let's code a Simple SFSB with a counter variable instance that will be used to keep track of the session:

package com.sample.ejb;

import javax.annotation.PostConstruct;
import javax.ejb.Remote;
import javax.ejb.Stateful;
import org.jboss.ejb3.annotation.Clustered;


public class  SampleBeanRemoteImpl implements SampleBeanRemote  {
    int counter=0;

    public void init() {
           System.out.println("EJB inited!");

    public int sum() {

               System.out.println("Value of the counter:"+counter);
               return counter;


And here's the corresponding SampleBeanRemote interface:

package com.sample.ejb;

public interface SampleBeanRemote {
    public int sum();


Important Notice If you are using Eclipse and JBoss Tools (3.3) the JBoss AS 7 Server library does not includes by default the libraries where the @Clustered annotation is contained. Until this issue is solved, you have to include the jboss-ejb3-ext-api-2.0.0.jar manually as shown by the following picture:

jboss cluster tutorial software

On the other hand, if you are using Maven to build your project, you need to add the following dependency in order to compile your Clustered EJB:



Related articles available on

JBoss Clustering a Web Application

Please Note: This article cover JBoss AS 4/5/6 releases. If you w

Clustering EJB 3 with JBoss AS

To cluster a stateless session bean in EJB 3 all you need to do i

JBoss monitoring HTTP Session replication

In this article we'll show how to monitor HTTPSession replication

How do I change multicast address of JBoss cluster ?

Since JBoss AS 4.0.3, the jboss.partition.udpGroup property can b

JBoss farming service

What is the farming service ? this article explains about it, als

WildFly HTTP Session in a cluster

This tutorial discusses in detail how to configure HTTP Session M