Currently SGESv2.x supports RMI-IIOP loadbalancing. But this loadbalancing is based on the InitialContext:when a new InitialContext() is created, a load balancing decision is made, binding that InitialContext to a replica, until the replica fails, at which point all requests using that InitialContext fail over to a new replica.
Refer :

The PRLB feature aims at addressing the requirement, where for the same EJB object of a stateless session bean, the method calls to the bean needs to be loadbalanced. An EJB instance is represented (in GlassFish) by a dynamic stub, which contains a reference to the endpoints. The loadbalancing of the calls happens in a round robin fashion. The list has the lifetime of the stub and anything
that clears or resets the list starts the PRLB process all over again. Hence, ideally an ejb lookup() would reset the list and restarts the
PRLB process.

In sun-ejb-jar.xml, a new optional boolean child element for the ejb element "per-request-load-balancing" is introduced.If per-request-load-balancing is set to true for a stateless session bean, per request load balancing will be enabled for invocations made through Remote EJB 2.x and 3.x client invocations on that bean. If set to false or not set, per request load balancing will not be enabled for the bean. The per-request-load-balancing element only applies to stateless session beans. Use of the element on other bean types will result in
a deployment error.

For example :



The sun-ejb-jar.xml needs to be updated as above and EJB jar needs to be redeployed.

As a verification check, you can verify that this is configured properly by looking for the following (FINE, in the CORBA logger) log message when the EJB is loaded:

"Setting per-request-load-balancing policyfor EJB "

Important requisites for PRLB feature to work :

1. The "per-request-load-balancing" property needs to be enabled in sun-ejb-jar.xml
2. If the client you are using is a Web Client, both EJB and Web Client needs to reside in the same JVM.

Client Example:

public class EJBClient {
public static void main(String args[]) {
try {
// only one lookup

Object objref = initContext.lookup("test.cluster.loadbalancing.ejb.TestSessionBeanRemo te");
myGreeterRemote = (TestSessionBeanRemote)PortableRemoteObject.narrow (objref,

} catch (Exception e) {

for (int i=0; i < 10; i++ ) {
// method calls in a loop.
String theMessage = myGreeterRemote.sayHello(Integer.toString(i));
System.out.println("got"+": " + theMessage);

Read More about [PRLB feature in GlassFish 2.1.1...