In Chapter 4, we introduced the Stateless Session Bean (SLSB), while talking about Enterprise Java Beans. By now, you should be aware that they do not hold state between client invocations, so the main benefit of clustering an SLSB is to balance the load between an array of servers. Consequently, the clustering policies are pretty simple. The following is a bare-bones clustered SLSB:
@Stateless
@Clustered
public class ClusteredBean implements ClusteredInt
{
public void doSomething()
{
// Do something
}
}
The @Clustered
annotation needs to be added before the class declaration level. That's all you need to make a clustered Stateless Session Bean.
If you don't want to stick to clustering defaults, you can configure some additional elements. Here's the same ClusteredBean
with customized clustering parameters:
@Stateless
@Clustered(loadBalancePolicy="FirstAvailable",partition="ClusterA")
public class ClusteredBean implements ClusteredInt
{
public void...