单个应用程序服务器实例中的单独应用程序中的EJB本地/远程接口

时间:2010-04-27 12:53:45

标签: java-ee weblogic ejb application-server oc4j

假设部署了两个EAR的单个应用程序服务器实例。第一个EAR使用远程EJB接口从第二个EAR调用EJB。

据传,即使使用远程接口实现invokation,应用服务器也知道所有内容都在同一个JVM中,并在内部使用具有本地接口机制的远程接口,即它不通过RMI调用方法,不会打开任何套接字,并不序列化/反序列化对象。

这是真的吗?如果有人对Weblogic 10.3.2和OC4j 10.1.3关于此问题的行为有任何反馈意见,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

不,这不是真的。如果ORB实现本地对象优化(有时是“并置对象”),那么它将不会打开任何套接字,但它将执行序列化/反序列化,这通常比编组更快。制作额外的对象副本是为了避免违反编程模型。

生成的存根启用此优化。这是一个示例界面:

public interface a extends Remote {
  public ArrayList test(ArrayList in1, ArrayList in2) throws RemoteException;
}

这是rmic -iiop -keep a:

的结果
public ArrayList test(ArrayList arg0, ArrayList arg1) throws java.rmi.RemoteException {
    if (!Util.isLocal(this)) {
        /* ... trim remote code ... */
    } else {
        ServantObject so = _servant_preinvoke("test",a.class);
        if (so == null) {
            return test(arg0, arg1);
        }
        try {
            Object[] copies = Util.copyObjects(new Object[]{arg0,arg1},_orb());
            ArrayList arg0Copy = (ArrayList) copies[0];
            ArrayList arg1Copy = (ArrayList) copies[1];
            ArrayList result = ((a)so.servant).test(arg0Copy, arg1Copy);
            return (ArrayList)Util.copyObject(result,_orb());
        } catch (Throwable ex) {
            Throwable exCopy = (Throwable)Util.copyObject(ex,_orb());
            throw Util.wrapException(exCopy);
        } finally {
            _servant_postinvoke(so);
        }
    }
}

当存根连接到本地对象时,它会调用ObjectImpl._servant_preinvoke来查找同一JVM中的servant(在您的情况下为EJB包装器)。然后,它复制输入参数(模拟编组),调用方法,并复制结果对象(再次模拟编组)。

我不是WebLogic专家。也就是说,本文档暗示WebLogic执行并置对象优化:

http://download.oracle.com/docs/cd/E13222_01/wls/docs61/cluster/object.html#1007328