ThreadLocal来存储Session

/**
 * 用ThreadLocal来存储Session,以便实现Session any where.
 * 
 */
public class ThreadLocalUtil {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static ThreadLocal<HttpSession> httpSessionThreadLocal = new ThreadLocal<HttpSession>();

    public static HttpSession getHttpSessionThreadLocal() {
        return ThreadLocalUtil.httpSessionThreadLocal.get();
    }

    public static void setHttpSessionThreadLocal(HttpSession httpSession) {
        ThreadLocalUtil.httpSessionThreadLocal.set(httpSession);
    }

    public static void remove() {
        ThreadLocalUtil.httpSessionThreadLocal.remove();
    }

}

 

posted @ 2021-06-25 15:16  表演给自己看的认真  阅读(339)  评论(0编辑  收藏  举报