Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 会话超时在Google应用程序引擎上不起作用_Java_Jsp_Google App Engine_Session_Google Cloud Datastore - Fatal编程技术网

Java 会话超时在Google应用程序引擎上不起作用

Java 会话超时在Google应用程序引擎上不起作用,java,jsp,google-app-engine,session,google-cloud-datastore,Java,Jsp,Google App Engine,Session,Google Cloud Datastore,我有一个简单的JSPServlet web应用程序,目前部署在Google应用程序引擎上。 我有一个实现HttpSessionListener的SessionListener来监视会话的创建和销毁 public class SessionListener implements HttpSessionListener { private int sessionCount = 0; @Override public void sessionCreated(HttpSessionEve

我有一个简单的JSPServlet web应用程序,目前部署在Google应用程序引擎上。 我有一个实现HttpSessionListener的SessionListener来监视会话的创建和销毁

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);
  }

}
在web.xml文件中,我已将以下配置设置为允许30分钟后自动会话超时:

<session-config>
    <session-timeout>30</session-timeout>
</session-config>
但是,当我在GAE上部署应用程序时,我在GAE管理页面的日志控制台中找不到空闲会话的打印输出。只有当我显式地点击调用的注销按钮时,会话才会被破坏

HttpSession session=request.getSession(false);
session.invalidate();
因此,我认为空闲会话在特定的设置时间之后永远不会被破坏。我可以注意到,随着新浏览器访问web应用程序,会话总数不断增加


我知道GAE处理会话的方式是:将会话存储在数据存储中,并在JVM中共享它们。但是,有没有办法使会话超时工作并将会话闲置一段时间?

调整GAE内置的SessionCleanupServlet为我解决了这个问题。更多详情:

"Session Destroyed: {sessionId} etc"
HttpSession session=request.getSession(false);
session.invalidate();