最佳实践: 如果 EJB 和 Servlet 在同一个 JVM 中,则使用“引用传递”
当 EJB 和其它应用程序组件在同一个 JVM 中时,使用“引用传递”调用语义避免了 RMI-IIOp 开销。EJB 1.1 规范声明方法调用是“值传递”。这意味着对于每个远程方法调用,在调用之前,先要将参数复制到堆栈上。然而,这种操作花费很大。通过指定“引用传递”,无 需进行复制就可以传递原始对象引用。这样,就会导致极大的性能改进。
读者: 开发人员,架构设计师
产品: WebSphere Application Server
版本: 3.0.2.x、3.5.x 和 4.0
平台: 全部
关键字: Servlet、JSp 和 EJB、引用传递(pass by Reference)、值传递(pass by Value)、RMI-IIOp、JVM
要在 WebSphere 高级版,版本 4.0 中设置“引用传递”,请完成下列步骤:
- 单击正在调试 Object Request Broker 的应用程序服务器中的 Services选项卡。
- 单击 Advanced选项卡。
- 选中 pass by Reference,然后单击 OK。
- 单击 Apply以保存更改。
- 停止并重新启动该应用程序服务器。
class SomeClass {应被取代的方法
RemoteObjectHome myRemoteHome;
RemoteObject myRemoteObject;
parameterObject myArgument;
void someMethod() {
myRemoteObject = myRemoteHome.create();
myArgument.setproperty("Before");
String newproperty = myRemoteObject.someRemoteMethod(myArgument);
// Both String newproperty and paremeterObject myArgument
// have been changed with the "Call By Reference"
}
}
class RemoteObjectBean implements SessionBean {
public String someRemoteMethod(paramterObject aparameter) {
if (aparameter.getproperty().equals("Before")) {
aparameter.setproperty("After");
}
return aparameter.getproperty();
}
}