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

stjauns 2008-11-22 05:46:27
分别用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的时间要多上一个数量级?
而且是每次执行方法都要多上一个数量级的时间。
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lisl2003 2008-12-01
  • 打赏
  • 举报
回复
不懂,标记,学习一下

6,787

社区成员

发帖
与我相关
我的任务
社区描述
JBoss技术交流
社区管理员
  • JBoss技术交流社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧