【原创】大叔问题定位分享(35)spring中session失效时间
spring项目中将sessionid对应的cookie过期时间设置很长,但是实际session还是在半个小时后失效,跟了一下代码,spring中session实现接口为
org.springframework.session.SessionRepository
public interface SessionRepository<S extends Session> {
S createSession();
void save(S var1);
S findById(String var1);
void deleteById(String var1);
}
这个接口有两个实现类:
MapSessionRepository
RedisOperationsSessionRepository
单机环境使用前者,分布式环境使用后者,来看后者代码:
org.springframework.session.data.redis.RedisOperationsSessionRepository
public RedisOperationsSessionRepository.RedisSession createSession() {
RedisOperationsSessionRepository.RedisSession redisSession = new RedisOperationsSessionRepository.RedisSession();
if(this.defaultMaxInactiveInterval != null) {
redisSession.setMaxInactiveInterval(Duration.ofSeconds((long)this.defaultMaxInactiveInterval.intValue()));
}
return redisSession;
}
org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession
RedisSession() {
this(new MapSession());
this.delta.put("creationTime", Long.valueOf(this.getCreationTime().toEpochMilli()));
this.delta.put("maxInactiveInterval", Integer.valueOf((int)this.getMaxInactiveInterval().getSeconds()));
this.delta.put("lastAccessedTime", Long.valueOf(this.getLastAccessedTime().toEpochMilli()));
this.isNew = true;
this.flushImmediateIfNecessary();
}
public boolean isExpired() {
return this.cached.isExpired();
}
org.springframework.session.MapSession
public boolean isExpired() {
return this.isExpired(Instant.now());
}
boolean isExpired(Instant now) {
return this.maxInactiveInterval.isNegative()?false:now.minus(this.maxInactiveInterval).compareTo(this.lastAccessedTime) >= 0;
}
可见是在创建session的时候设置两个时间,
lastAccessedTime
maxInactiveInterval
如果 当前时间 - maxInactiveInterval > lastAccessedTime 就会认为session过期,设置的方法:
@EnableRedisHttpSession(maxInactiveIntervalInSeconds=2000)
【原创】大叔问题定位分享(35)spring中session失效时间的更多相关文章
- 关于Flask-Login中session失效时间的处理
最近需要使用Python开发web系统,主要用到的框架就是Flask,前端使用Jinja2模板引擎和Bootstrap,web容器使用Cherrypy,其中关于Login管理的使用了Flask-Log ...
- 【原创】大叔问题定位分享(27)spark中rdd.cache
spark 2.1.1 spark应用中有一些task非常慢,持续10个小时,有一个task日志如下: 2019-01-24 21:38:56,024 [dispatcher-event-loop-2 ...
- 【原创】大叔问题定位分享(11)Spark中对大表子查询加limit为什么会报Broadcast超时错误
当两个表需要join时,如果一个是大表,一个是小表,正常的map-reduce流程需要shuffle,这会导致大表数据在节点间网络传输,常见的优化方式是将小表读到内存中并广播到大表处理,避免shuff ...
- 【原创】大叔问题定位分享(7)Spark任务中Job进度卡住不动
Spark2.1.1 最近运行spark任务时会发现任务经常运行很久,具体job如下: Job Id ▾ Description Submitted Duration Stages: Succeed ...
- 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil
openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...
- 【原创】大叔问题定位分享(34)Spring的RestTemplate请求json数据后内容被修改
先看代码 org.springframework.web.client.RestTemplate public RestTemplate() { this.messageConverters = ne ...
- 【原创】大叔问题定位分享(3)Kafka集群broker进程逐个报错退出
kafka0.8.1 一 问题现象 生产环境kafka服务器134.135.136分别在10月11号.10月13号挂掉: 134日志 [2014-10-13 16:45:41,902] FATAL [ ...
- 【原创】大叔问题定位分享(28)openssh升级到7.4之后ssh跳转异常
服务器集群之间忽然ssh跳转不通 # ssh 192.168.0.1The authenticity of host '192.168.0.1 (192.168.0.1)' can't be esta ...
- 【原创】大叔问题定位分享(6)Dubbo monitor服务iowait高,负载高
一 问题 Dubbo monitor所在服务器状态异常,iowait一直很高,load也一直很高,监控如下: iowait如图: load如图: 二 分析 通过iotop命令可以查看当前系统中磁盘io ...
随机推荐
- axios的get请求无法设置Content-Type
最近在与后端的项目对接中,接口工具使用了axios这个东西.怎么说那 ,反正有很多坑,在后端的请求中要设置GET 请求中要设置header中的Content-Type为application/json ...
- Java面试题整理(转载)
转载地址:https://blog.csdn.net/matry521/article/details/52210139
- 【Makefile】Makefile的自动化变量$@、$^ 、$<等
所谓自动化变量,就是这种变量会把“模式”中所定义的一系列的文件自动地挨个取出,直至所有的符合模式的文件都取完了.这种自动化变量只应出现在规则的命令中. $@ 表示规则中的目标文件集.在模式规则中,如果 ...
- Matlab获取一个文件夹下所有文件名
Matlab获取一个文件夹下所有文件名: fileFolder=fullfile('D:\MATLAB\bin\trc'); dirOutput=dir(fullfile(fileFolder,'*. ...
- AES对称加密解密类
import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.Se ...
- python -v 和-V
python -v 小写v:这是版本信息,包括库版本 python -V 大写v:只看python的版本
- [Java复习] Java基础 Basic
Q1面向对象 类.对象特征? 类:对事物逻辑算法或概念的抽象,描述一类对象的行为和状态. OOP三大特征,封装,继承,多态 封装:隐藏属性实现细节,只公开接口.将抽象的数据和行为结合,形成类.目的是简 ...
- [Python]正则匹配字符串 | 蒲公英二维码图片url
代码示例: import re def Find(string): # findall() 查找匹配正则表达式的字符串 url = re.findall('http[s]?://(?:[a-zA-Z] ...
- Centos安装openjdk
转载自:https://blog.csdn.net/youzhouliu/article/details/51183115 openjdk在linux各个平台下安装源中可以找到. 命令查找安装源中有什 ...
- 手写web框架之实现Bean容器
实现Bean容器 使用ClassHelper可以获取所加载的类,但无法通过类来实例化对象,因此我们需要提供一个反射工具类,让它封装java反射相关的API,对外提供更好用的工具方法.将该类命名为 ...