zoukankan      html  css  js  c++  java
  • 超时

    1. tomcat的session超时怎么做的

    有专门的后台线程每隔10秒(sleep 10l,可以配置)处理一次是否过期

    专门的线程

    org.apache.catalina.core.ContainerBase.ContainerBackgroundProcessor

    触发过期检查的地方:

    public void run() {
                while (!threadDone) {
                    try {
                        Thread.sleep(backgroundProcessorDelay * 1000L);
                    } catch (InterruptedException e) {
                        ;
                    }
                    if (!threadDone) {
                        Container parent = (Container) getMappingObject();
                        ClassLoader cl = 
                            Thread.currentThread().getContextClassLoader();
                        if (parent.getLoader() != null) {
                            cl = parent.getLoader().getClassLoader();
                        }
                        processChildren(parent, cl);
                    }
                }
            }

    Thread.sleep(backgroundProcessorDelay * 1000L); backgroundProcessorDelay 秒钟检查一次。backgroundProcessorDelay 在StandardEngine设置的是10 也就是10s钟检查一次。可以理解成session超时默认精度10s

    threadDone 这个标志会在stop的时候置成true,以使得能循环能正常结束

    处理是否过期

    if (maxInactiveInterval >= 0) { 
                long timeNow = System.currentTimeMillis();
                int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
                if (timeIdle >= maxInactiveInterval) {
                    expire(true);
                }
            }

    处理过期的具体方法:

    org.apache.catalina.session.StandardSession.expire(boolean)

    --EOF--

  • 相关阅读:
    HTML音频/视频DOM 参考手册
    HTML5 应用程序缓存 和 视频
    HTML 5 新的Input类型
    快速开发平台消息通知中心之短信发送
    设计模式之单例设计模式
    反射
    多线程之线程安全
    01-sql优化及索引
    多线程之线程状态
    shell/linux定时清理日志文件
  • 原文地址:https://www.cnblogs.com/simoncook/p/5404505.html
Copyright © 2011-2022 走看看