Reputation: 179
I noticed that my app is very slow sometimes, so I've done some tests. It's a very simple web app. One servlet gets some parameters than stores them. Everything's fine except one thing. It takes too long to get a parameter for the first time. It doesn't matter which parameter I try to get, but for the first time it is very slow. The strange thing is this doesn't happen always. Sometimes getting a parameter for the first time is not slow.
My code looks like this
request.getParameter("paramName");
request.getParameter("paramName2");
request.getParameter("paramName3");
Getting "paramName" is slow. Getting the others is very fast.
By slow I mean : 200-800 millisec
By very fast I mean: ~0 millisec
(in the code snippet, I didn't write the performance test, but I'm using System.currentTimeMillis()
)
UPDATE
I've exported my project into a .WAR file, and deployed it to Tomcat. Everything's fine. So I think this problem is related to Eclipse or something.
Upvotes: 3
Views: 2179
Reputation: 1108722
Sounds like a bug in Eclipse's builtin webbrowser that it doesn't send the Content-Length
header correctly. I can't tell from experience as I've never used it seriously. I always deploy the project to the integrated Tomcat or Glassfish, start it and then just open the page in a real webbrowser (Firefox, Chrome, Safari, IE, etc, which you run independently from Eclipse). This has the major benefit that you can use any of the browser's plugins and addons which can greatly ease development such as Firebug and consorts.
If you insist in using the webbrowser inside Eclipse, try changing the webbrowser used by going to Window > Web Browser and choosing other than Internal Web Browser.
Upvotes: 1
Reputation: 75376
Do you have enough memory? You need a lot when working with Eclipse and a deployment server, and it Sounds like swapping.
Upvotes: 0
Reputation: 1500535
I suspect that the parameters may be parsed lazily - when you first ask for a parameter, it may parse everything, storing them for efficient access later.
However, 200ms sounds like an awfully long time... is this when you're running under a debugger?
Of course, this is entirely dependent on your servlet container.
Upvotes: 2