您的位置:首页 > 其它

超时

2016-04-18 15:00 204 查看
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--
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: