在Google App Engine上扩展httpservlet泄漏请求 [英] extending httpservlet on google app engine leaks requests

查看:32
本文介绍了在Google App Engine上扩展httpservlet泄漏请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在Google App Engine上遇到的这个问题感到困惑.

我创建了几个servlet,所以我创建了一个基类来做一些基本的重复工作.像这样:

 公共类MyBase扩展HttpServlet {受保护的字符串someValue1;受保护的字符串someValue2;受保护的void设置(HttpServletRequest要求,HttpServletResponse响应){someValue1 = req.getParameter("paramName1");someValue2 = req.getParameter("paramName2");} 

和servlet:

 公共类MyServlet扩展了MyBase {@Override公共无效doGet(最终HttpServletRequest请求,最终的HttpServletResponse响应){super.setup(req,resp);doWork(someValue1);doOtherWork(someValue2);} 

足够简单-通常正常运行,并且在本地服务器上运行时,任何数量的负载测试都可以正常工作.此外,在GAE上进行的测试适用于测试实例.在我的生产实例上(仅在生产中),同时有1000个同时用户,someValue1和someValue2的值成为两个不同用户的请求!Servlet将在99%的时间内工作,每100个请求中就有1个最终来自不同请求的参数.没有道理,但它正在发生.

这显然是实际代码的简化版本,但是我已经使用集成测试来复制了它.

也许我错过了一些有关扩展httpservlet的细微差别?

解决方案

使用HttpServlet,最好不要使用实例变量,因为HttpServlet在会话之间可以重用.

通常,对于Java EE容器,仅创建1个MyServlet实例,并为从运行 doService -> doGet

要快速解决您的问题,

  @Override//性能受到很大影响.公共同步void doGet(final HttpServletRequest req,最终的HttpServletResponse响应){ 

或使用 resp.setAttribute();

I'm baffled by this problem I encountered on Google App Engine.

I created several servlets, so I created a base class to do some basic repeated work. Like this:

public class MyBase extends HttpServlet {

      protected String someValue1;
      protected String someValue2;

      protected void setup(HttpServletRequest req, HttpServletResponse resp)   {

         someValue1 = req.getParameter("paramName1");
         someValue2 = req.getParameter("paramName2");

}

and the servlet:

public class MyServlet extends MyBase {



    @Override
    public void doGet(final HttpServletRequest req,
                      final HttpServletResponse resp)  {

         super.setup(req, resp); 
         doWork(someValue1);
         doOtherWork(someValue2);

}

simple enough - this normally works perfectly and when running on a local server any amount of load testing works just fine. Also, testing on GAE works on test instances. On my production instance, and only on production, with 1000's of simultaneous users the value of someValue1 and someValue2 become the requests of two different users! Servlets will work 99% of the time, 1 out of 100 requests end up with parameters from different requests. Makes no sense but it's happening.

This is obviously a simplified version of the actual code, but I've reproduced it using integration tests.

Perhaps i'm missing some nuance about extending httpservlet?

解决方案

Using HttpServlet, it is better not to use instance variable, because the HttpServlet is reused between session.

It is usually for a Java EE container to create only 1 instance of MyServlet and create a thread for each request received from client running doService -> doGet

To quick fix solve your problem, either

@Override //performance suffers greatly.
    public sychronized void doGet(final HttpServletRequest req,
                      final HttpServletResponse resp)  {

Or use resp.setAttribute();

这篇关于在Google App Engine上扩展httpservlet泄漏请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆