首先连接到Glassfish v3的速度很慢
问题描述:
当试图从swing应用程序连接到glassfish v3时,它第一次非常慢。需要4-10秒。 在客户端:
首先连接到Glassfish v3的速度很慢
public void myMethod(){
NewSessionBeanRemote facade;
try {
InitialContext ic = new InitialContext();
facade = (NewSessionBeanRemote) ic.lookup(NewSessionBeanRemote.class.getName());
target.setText(facade.businessMethod());
} catch (NamingException ex) {
ex.printStackTrace();
}
}
在服务器端:
@Stateless
public class NewSessionBean implements NewSessionBeanRemote {
@Override
public String businessMethod() {
return String.valueOf(Math.random() + 121 + 300);
}
}
@Remote
public interface NewSessionBeanRemote {
String businessMethod();
}
我需要什么环境中的变化?
答
当试图从swing应用程序连接到glassfish v3时,它第一次非常慢。
可能是由于lazy initialization of Application Server services(EJB容器,连接池,...)。
需要4-10秒。
接下来的调用怎么样?
答
这就是Java EE的工作原理。当页面首次被调用时,所有的JSP都被编译并且所有的bean都被实例化。即使您关闭延迟初始化,您也必须在启动时等待相同的时间。
引文从wikipedia.org https://en.wikipedia.org/wiki/JavaServer_Pages#Compiler
甲JavaServer页编译器是一个分析的JSP的程序,并且 将它们转换为可执行的Java Servlet的。这种类型的程序 通常嵌入到应用程序服务器中,并在第一次访问JSP时自动运行 ,但页面也可能被预编译为 以获得更好的性能,或者编译为构建过程的一部分,以 进行错误测试。
如果你愿意,你可以尝试预编译的一切,看看它是否效果更好:
http://www.avajava.com/tutorials/lessons/how-do-i-precompile-my-jsps.html
我之前没有带使用Glassfish的,但可能这仅仅是标准的Java虚拟机器冷启动? – Syntax 2010-09-14 08:57:47
服务器正在运行。所有其他时间我都会立即获得数据。 – Dmitry 2010-09-14 09:02:34