第一个请求的servlet响应时间很慢 [英] servlet response time is slow for first request
问题描述
Servlet
响应时间仅对第一次请求缓慢
Servlet
response time slow only for 1st request
响应时间
第一个请求
是10.5秒。
进一步请求
2.5秒。
从少数 java
资源到达知道 servlet
在第一个请求期间第一次加载所需的
并重新使用相同的类
请求
,因此延迟
From few java
resources i got to know that the servlet
loads the required classes
for the first time during the first request
and reuses the same for further requests
and hence the delay
修复1:
我在 servlet中创建了
执行虚拟请求
init()
方法后立即执行。
Fix 1:
I created a dummy request
within the servlet
immediately after the execution of init()
method.
响应时间:所有人都需要2.5秒通过用户代理请求。
Response time : 2.5 seconds for all requests through user agents.
修复2:
我尝试加载可能的类
启动
servlet
响应时间:对于第一个请求
是6秒econds。其他请求需要2.5秒。
Response time : for first request
is 6 seconds. 2.5 seconds for other requests.
是否还有其他可能实现相同的目标,因为我认为方法1 需要在网址更改时更改代码应用程序(端口号,资源路径等)和方法2 的响应时间是不够的。
Is there are any other possibility of achieving the same because i believe that method 1 needs code change when there is a change in the url of the application (port number, resource path, etc) and response time of method 2 is not sufficient.
我已经设置了 loadOnStartup = 1
我的 servlet
。
推荐答案
你也可以在web.xml中使用load-on-startup param在starttime上加载和intitiliaze你的servlet。
you can also use load-on-startup param in web.xml to load and intitiliaze your servlet on starttime.
<servlet>
<servlet-name>MyServlet</servlet-name>
<display-name>My Servlet</display-name>
<servlet-class>com.foo.MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
这篇关于第一个请求的servlet响应时间很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!