jboss-4.2.3.GA分别部署EJB1和EJB3,为何在客户端调用速度相差这么多?
分别用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的时间要多上一个数量级?
而且是每次执行方法都要多上一个数量级的时间。
服务器端就一个自定方法:
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的时间要多上一个数量级?
而且是每次执行方法都要多上一个数量级的时间。
...全文
相关推荐
EJB3.0+JBOSS4.2.2GA集群
总的来说,"EJB3.0+JBOSS4.2.2GA集群"意味着开发者正在构建一个基于EJB 3.0的分布式应用程序,并使用JBoss AS 4.2.2 GA版本来支持集群部署,以提高系统的可靠性和性能。
JBoss 4.2.3.GA应用服务器配置与优化
JBoss 4.2.3.GA是JBoss应用服务器的一个经典版本,运行在Java Enterprise Edition (J2EE) 规范上。它为开发和部署企业级应用程序提供了一个全面的平台,包括支持EJB、Servlets、JSP、JMS等多种技术。在本章中,我们深入探讨了JBoss应用服务器中应用程序的部署与管理。首先介绍了部署描述符的作用和如何配置,然后具体讲解了使用不同的工具如命令行工具、管理控制台和IDE插件进行应用部署。
jboss-4.2.2.GA
**Java EE 5兼容性**:JBoss 4.2.2.GA支持Java Platform, Enterprise Edition 5(Java EE 5)标准,包括EJB 3.0、JSF 1.2、JPA
jboss-4.2.3
在JBoss 4.2.3中,有几个关键的知识点值得深入探讨:1.
jboss-5.0.0.GA
**JBoss AS 5.0概述**: JBoss AS 5.0是基于Java EE 5规范的,支持包括EJB 3.0、JSF 1.2、JPA 1.0、JMS 1.1、Servlet 2.5和JSP 2.1


