提交 a90a803e authored 作者: Thomas Mueller's avatar Thomas Mueller

Formatting

上级 18cb1b4a
......@@ -9,36 +9,36 @@ import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
* Similar to ThreadLocal, except that it allows it's data to be read from other threads - useful for debugging info.
* Similar to ThreadLocal, except that it allows it's data to be read from other
* threads - useful for debugging info.
*
* @param <T> the type
*/
public class DebuggingThreadLocal<T>
{
private final ConcurrentHashMap<Long, T> map = new ConcurrentHashMap<Long, T>();
public DebuggingThreadLocal() {
}
public void set(T value) {
map.put(Thread.currentThread().getId(), value);
}
public void remove() {
map.remove(Thread.currentThread().getId());
}
public T get() {
return map.get(Thread.currentThread().getId());
}
/**
* @return a HashMap containing a mapping from thread-id to value
*/
public HashMap<Long,T> getSnapshotOfAllThreads() {
return new HashMap<Long,T>(map);
}
public T deepCopy(T value) {
return value;
}
public class DebuggingThreadLocal<T> {
private final ConcurrentHashMap<Long, T> map = new ConcurrentHashMap<Long, T>();
public void set(T value) {
map.put(Thread.currentThread().getId(), value);
}
public void remove() {
map.remove(Thread.currentThread().getId());
}
public T get() {
return map.get(Thread.currentThread().getId());
}
/**
* @return a HashMap containing a mapping from thread-id to value
*/
public HashMap<Long, T> getSnapshotOfAllThreads() {
return new HashMap<Long, T>(map);
}
public T deepCopy(T value) {
return value;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论