CRITICAL
Rule Definition
Since stateful session beans cannot be pooled and reused like stateless
beans, there is a real danger of accumulating too many of them if the remove method is not implemented or if this method is not called.
Remediation
Call this method from the client side
Violation Code Sample
@Remote
public interface MyRemoteBean {
public int aMethod();
public void removeMethod();
}
@Stateful
public class MyBean implements MyRemoteBean {
...
public int aMethod() {
...
}
@Remove
public void removeMethod() {
...
}
}
public class Client { // VIOLATION
private static @EJB MyRemoteBean myClientBean;
public static void main(String[] args) {
Client client = new Client(args);
client.callServer();
}
public Client(String[] args) {}
public void callServer() {
try {
int res=myClientBean.aMethod();
}catch(Exception e){
e.printStackTrace();
}
}
}
Fixed Code Sample
@Remote
public interface MyRemoteBean {
public int aMethod();
public void removeMethod();
}
@Stateful
public class MyBean implements MyRemoteBean {
...
public int aMethod() {
...
}
@Remove
public void removeMethod() {
...
}
}
public class Client {
private static @EJB MyRemoteBean myClientBean;
public static void main(String[] args) {
Client client = new Client(args);
client.callServer();
}
public Client(String[] args) {}
public void callServer() {
try {
int res=myClientBean.aMethod();
myClientBean.removeMethod(); // FIXED
}catch(Exception e){
e.printStackTrace();
}
}
}
Reference
EJB 3 in Action (ISBN 1-933988-34-7) page 94
http://what-when-how.com/enterprise-javabeans-3/stateful-session-beans-ejb-3/
Related Technologies
Technical Criterion
Efficiency - Memory, Network and Disk Space Management
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.