jboss-4.2.3.GA分别部署EJB1和EJB3,为何在客户端调用速度相差这么多?

stjauns stjauns 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
分别用EJB1(J2EE1.3)和EJB3(Java EE 5)实现了下面的功能:
服务器端就一个自定方法:

public String doThings(String para) throws EJBException {
System.out.println(para);
return "did : " + para;
}

在客户端调用EJB1的代码:
long ll = System.currentTimeMillis();
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://218.16.125.93");
AllTestHome home = null;
AllTest test = null;
InitialContext ctx = new InitialContext(properties);
System.out.println("ctx init ok!" + (System.currentTimeMillis() - ll));
ll = System.currentTimeMillis();
Object obj = ctx.lookup(AllTestHome.JNDI_NAME);
home = (AllTestHome) PortableRemoteObject
.narrow(obj, AllTestHome.class);
test = home.create();
System.out.println("remote lookup ok!"
+ (System.currentTimeMillis() - ll));
ll = System.currentTimeMillis();
System.out.println(test.doThings("select now();"));
System.out.println("function execute ok!"
+ (System.currentTimeMillis() - ll));

在客户端调用EJB3代码:
long ll = System.currentTimeMillis();
Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "jnp://218.16.125.93");
InitialContext ctx = new InitialContext(properties);
System.out.println("ctx init ok!" + (System.currentTimeMillis() - ll));
ll = System.currentTimeMillis();
SessionallRemote remote = (SessionallRemote) ctx
.lookup("Sessionall/remote");
System.out.println("remote lookup ok!"
+ (System.currentTimeMillis() - ll));
ll = System.currentTimeMillis();
System.out.println(remote.doThings("select now();"));
System.out.println("function execute ok!"
+ (System.currentTimeMillis() - ll));

在客户端分别执行两端代码三次,都成功了,但是输入如下:
EJB1:
ctx init ok!31
remote lookup ok!687
did : select now();
function execute ok!32

ctx init ok!31
remote lookup ok!719
did : select now();
function execute ok!47

ctx init ok!32
remote lookup ok!703
did : select now();
function execute ok!47

EJB3:
ctx init ok!47
remote lookup ok!422
Doing:select now();
function execute ok!360

ctx init ok!46
remote lookup ok!469
Doing:select now();
function execute ok!406

ctx init ok!47
remote lookup ok!453
Doing:select now();
function execute ok!422

我的疑问在于:
function execute ok!代表的执行自定义方法的时间,为什么EJB3的时间比EJB1的时间要多上一个数量级?
而且是每次执行方法都要多上一个数量级的时间。
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
stjauns
JBoss技术交流 6,786 成员 2,557 内容