192 Star 1.6K Fork 454

Gitee Community / bullshit-codes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
JavaThreadLocal 948 Bytes
一键复制 编辑 原始数据 按行查看 历史
卖男孩的小炸弹 提交于 2023-07-19 05:47 . add JavaThreadLocal.
public class ThreadLocalUtil {
private static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal() {
protected Map<String, Object> initialValue() {
return new HashMap(0);
}
};
public static Map<String, Object> getThreadLocal() {
return threadLocal.get();
}
public static Object get(String key) {
Map map = (Map) threadLocal.get();
return map.get(key);
}
public static Object get(String key, Object defaultValue) {
Map map = (Map) threadLocal.get();
return map.get(key) == null ? defaultValue : map.get(key);
}
public static void set(String key, Object value) {
Map map = (Map) threadLocal.get();
map.put(key, value);
}
public static void set(Map<String, Object> keyValueMap) {
Map map = (Map) threadLocal.get();
map.putAll(keyValueMap);
}
public static Object remove(String key) {
Map map = (Map) threadLocal.get();
return map.remove(key);
}
}
1
https://gitee.com/gitee-community/bullshit-codes.git
git@gitee.com:gitee-community/bullshit-codes.git
gitee-community
bullshit-codes
bullshit-codes
master

搜索帮助