博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring+shiro session与线程池的坑
阅读量:4625 次
发布时间:2019-06-09

本文共 1579 字,大约阅读时间需要 5 分钟。

在java web编程中,经常使用shiro来管理session,也确实好用

  1. shiro来获取session的方式

SecurityUtils.getSubject().getSession()

其中SecurityUtils的getSubject代码如下

/**     * Returns the currently accessible {@code Subject} available to the calling code depending on     * runtime environment.     * 

* This method is provided as a way of obtaining a {@code Subject} without having to resort to * implementation-specific methods. It also allows the Shiro team to change the underlying implementation of * this method in the future depending on requirements/updates without affecting your code that uses it. * * @return the currently accessible {@code Subject} accessible to the calling code. * @throws IllegalStateException if no {@link Subject Subject} instance or * {@link SecurityManager SecurityManager} instance is available with which to obtain * a {@code Subject}, which which is considered an invalid application configuration * - a Subject should always be available to the caller. */ public static Subject getSubject() { Subject subject = ThreadContext.getSubject(); if (subject == null) { subject = (new Subject.Builder()).buildSubject(); ThreadContext.bind(subject); } return subject; }

  

 

Subject subject = ThreadContext.getSubject();

获取进程上下文,这个存在了问题,如果在使用线程池,获取的就是线程池里面的session,如果线程池为配置过期时间,那么线程池里面的线程一直不变,就会出现在线程池里面getsession就会是上一次的session,导致获取session失败

 

线程池原理可参考

转载于:https://www.cnblogs.com/ytxiao/p/11082523.html

你可能感兴趣的文章
spi驱动无法建立spidev问题
查看>>
ANDROID开发之SQLite详解
查看>>
如何依靠代码提高网络性能
查看>>
Zookeeper要安装在奇数个节点,但是为什么?
查看>>
discuz 微社区安装记录
查看>>
[BZOJ4824][Cqoi2017]老C的键盘 树形dp+组合数
查看>>
配置的热更新
查看>>
MySQL事务的开启与提交,autocommit自动提交功能
查看>>
PriorityQueue
查看>>
CODEVS1403 新三国争霸
查看>>
iOS 环信离线推送
查看>>
WPFTookit Chart 高级进阶
查看>>
雷云Razer Synapse2.0使用测评 -第二次作业
查看>>
django上传文件
查看>>
CVPR2013-papers
查看>>
PHP之时间函数
查看>>
Python open()完整参数
查看>>
django里面DTL使用for循环时,获取当前循环次数使用{{forloop.counter}}
查看>>
Java基础——Java集合(二)
查看>>
详解如何让Android UI设计性能更高效
查看>>