标签:
ThreadLocal并不难理解,我总结的最简单的理解就是:
@SuppressWarnings("unchecked")
public class UserSession {
private static final ThreadLocal SESSION_MAP = new ThreadLocal();
protected UserSession() {
}
public static Object get(String attribute) {
Map map = (Map) SESSION_MAP.get();
return map.get(attribute);
}
public static <T> T get(String attribute, Class<T> clazz) {
return (T) get(attribute);
}
public static void set(String attribute, Object value) {
Map map = (Map) SESSION_MAP.get();
if (map == null) {
map = new HashMap();
SESSION_MAP.set(map);
}
map.put(attribute, value);
}
}
ThreadLocal实现session中用户信息 的线程间共享(精)
标签:
原文地址:http://www.cnblogs.com/winner-0715/p/5609095.html