If you want more details i.e. want to see the threadlocal variables for all the threads following code might help:
public static String printThreadLocal() {
StringBuilder sb = new StringBuilder();
try {
Thread[] tarray = new Thread[Thread.activeCount()];
Thread.enumerate(tarray);
for (int i = 0; i < tarray.length; i++) {
Field threadLocalField = Thread.class.getDeclaredField("threadLocals");
threadLocalField.setAccessible(true);
Object o1 = threadLocalField.get(tarray[i]); //Thread.currentThread());
Field tableField = o1.getClass().getDeclaredField("table");
tableField.setAccessible(true);
Object[] o2 = (Object[]) tableField.get(o1);
for (Object temp : o2) {
if (temp != null) {
Field valueField = temp.getClass().getDeclaredField("value");
valueField.setAccessible(true);
Object o3 = valueField.get(temp);
sb.append(o3.toString() + "\n");
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return sb.toString();
}
You can add MyClass.printThreadLocal()
to Expressions
.