JBoss.org Community Documentation

3.3. Stateless Session Bean in EJB 3.0

To cluster a stateless session bean in EJB 3.0, all you need to do is to annotate the bean class withe the @Clustered annotation. You can pass in the load balance policy and cluster partition as parameters to the annotation. The default load balance policy is org.jboss.ha.framework.interfaces.RandomRobin and the default cluster is DefaultPartition. Below is the definition of the @Cluster annotation.

public @interface Clustered {
   Class loadBalancePolicy() default LoadBalancePolicy.class;
   String partition() default  "${jboss.partition.name:DefaultPartition}";

Here is an example of a clustered EJB 3.0 stateless session bean implementation.

public class MyBean implements MySessionInt {
   public void test() {
      // Do something cool

The @Clustered annotation can also be omitted and the clustering configuration applied in jboss.xml: