Spring+shiro session与线程池的坑

在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.
     * <p/>
     * 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 <em>always</em> 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/articles/11081136.html

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值