简体   繁体   English

会话超时在 Google App Engine 上不起作用

[英]Session Timeout does not work on Google App Engine

I have a simple JSP Servlet web app currently deployed on Google App Engine.我有一个当前部署在 Google App Engine 上的简单 JSP Servlet Web 应用程序。 I have a SessionListener implementing HttpSessionListener to monitor creation and destroying of sessions.我有一个 SessionListener 实现 HttpSessionListener 来监视会话的创建和销毁。

public class SessionListener implements HttpSessionListener {

  private int sessionCount = 0;

  @Override
  public void sessionCreated(HttpSessionEvent event) {
    // TODO Auto-generated method stub
    synchronized (this) {
        sessionCount++;
    }

    System.out.println("Session Created: " + event.getSession().getId());
    System.out.println("Total Sessions: " + sessionCount);
  }

  @Override
  public void sessionDestroyed(HttpSessionEvent event) {
    // TODO Auto-generated method stub
    synchronized (this) {
        sessionCount--;
    }
    System.out.println("Session Destroyed: " + event.getSession().getId() + ", " + event.getSession().getAttribute("loginName"));
    System.out.println("Total Sessions: " + sessionCount);
  }

}

In the web.xml file I have set the following config to allow automated session timeout after 30 minutes:在 web.xml 文件中,我设置了以下配置以允许 30 分钟后自动会话超时:

<session-config>
    <session-timeout>30</session-timeout>
</session-config>

In the appengine-web.xml file I have set the following config:在 appengine-web.xml 文件中,我设置了以下配置:

<sessions-enabled>true</sessions-enabled>

When deployed and running locally sessions idle for 30 minutes get destroyed after 30 minutes as I could see in the console正如我在控制台中看到的那样,当部署和运行本地会话空闲 30 分钟时,30 分钟后会被销毁

"Session Destroyed: {sessionId} etc"

However when I got the app deployed on GAE I could not find the printout in the Log console of the GAE Admin page for the idle session.但是,当我在 GAE 上部署应用程序时,我无法在 GAE 管理页面的日志控制台中找到空闲会话的打印输出。 A session only gets destroyed when I explicitly hit the Logout button that calls只有当我明确点击调用的注销按钮时,会话才会被破坏

HttpSession session=request.getSession(false);
session.invalidate();

So I think idle sessions never get destroyed after the specific set time.所以我认为空闲会话在特定的设置时间之后永远不会被破坏。 And I could notice that the total count of sessions kept increasing with new browsers accessing the web app.我可以注意到,随着新浏览器访问 Web 应用程序,会话总数不断增加。

I know GAE deals with session their way: store sessions in the Datastore and share them throughout JVMs.我知道 GAE 以自己的方式处理会话:将会话存储在数据存储中并在整个 JVM 中共享它们。 However is there a way to make session timeout work and destroy the sessions idle for a period of time?但是有没有办法让会话超时工作并破坏会话空闲一段时间?

Tweaking the GAE built-in SessionCleanupServlet solved the problem for me.调整 GAE 内置的 SessionCleanupServlet 为我解决了这个问题。 More details: https://web.archive.org/web/20130708093908/http://www.radomirml.com/blog/2011/03/26/cleaning-up-expired-sessions-from-app-engine-datastore/更多详情: https : //web.archive.org/web/20130708093908/http : //www.radomirml.com/blog/2011/03/26/cleaning-up-expired-sessions-from-app-engine-datastore /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM