Servlet请求get参数的表现

发布于 2024-08-28 02:38:00 字数 526 浏览 11 评论 0原文

我注意到我的应用程序有时非常慢,所以我做了一些测试。 这是一个非常简单的网络应用程序。一个 servlet 获取一些参数而不是存储它们。 一切都很好,除了一件事。第一次获取参数时间过长。我尝试获取哪个参数并不重要,但第一次它非常慢。奇怪的是,这种情况并不总是发生。有时候第一次获取参数并不慢。

我的代码看起来像这样

request.getParameter("paramName");
request.getParameter("paramName2");
request.getParameter("paramName3");

获取“paramName”很慢。获得其他人的速度非常快。

我所说的慢是指:200-800 毫秒 我所说的非常快是指:~0 毫秒 (在代码片段中,我没有编写性能测试,但我使用System.currentTimeMillis()

更新

我已将我的项目导出到 .WAR 文件中,并将其部署到雄猫。一切都很好。所以我认为这个问题与Eclipse什么的有关。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晨曦÷微暖 2024-09-04 02:38:01

我怀疑这些参数可能会被延迟解析 - 当您第一次请求参数时,它可能会解析所有内容,并将它们存储起来以便以后有效访问。

然而,200 毫秒听起来太长了……这是在调试器下运行时的情况吗?

当然,这完全取决于您的 servlet 容器。

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.

浅唱々樱花落 2024-09-04 02:38:01

听起来是 Eclipse 内置 Web 浏览器中的一个错误,它无法正确发送 Content-Length 标头。我无法从经验中判断,因为我从未认真使用过它。我总是将项目部署到集成的 Tomcat 或 Glassfish,启动它,然后在真实网络浏览器(Firefox、Chrome、Safari、IE 等,独立于 Eclipse 运行)中打开页面。这样做的主要好处是您可以使用任何浏览器的插件和附加组件,这可以极大地简化开发,例如 Firebug 和 consorts。

如果您坚持在 Eclipse 中使用 Web 浏览器,请尝试通过转到 Window > 来更改所使用的 Web 浏览器。 Web 浏览器并选择除内部 Web 浏览器之外的其他浏览器。

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.

不奢求什么 2024-09-04 02:38:01

你有足够的内存吗?使用 Eclipse 和部署服务器时您需要很多东西,这听起来像是交换。

Do you have enough memory? You need a lot when working with Eclipse and a deployment server, and it Sounds like swapping.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文