用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 @ 2022-12-21 10:01  雨飞  阅读(121)  评论(0)    收藏  举报