URLConnection getInputStream()/openStream() is slow for the first time
I am executing the following line, as soon as the Tomcat server(5.5.28) is started..
URL url = new URL("http://localhost:80/servlets/ConnectionCheckServlet");
URLConnection uc = url.openConnection();
long t=System.currentTimeMillis();
//InputStream content = (InputStream)uc.getInputStream();
InputStream content = (InputStream)url.openStream();
System.out.println("Time diff: "+(System.currentTimeMillis()-t));
The Timediff in millisecs got printed as Time开发者_Python百科 diff: 5141 (> 5 Seconds)
For the subsequent call on the same servlet or for a different servlet, the time diff is actually less than a second.
Will the first time delay, some thing to do with Tomcat intialization??
I guess it could be due to compilation and/or caching of the servlet which could occur the first time accessed.
精彩评论