diff --git a/src/main/java/com/alibaba/ttl/TransmittableThreadLocal.java b/src/main/java/com/alibaba/ttl/TransmittableThreadLocal.java index d062504af..13e523897 100644 --- a/src/main/java/com/alibaba/ttl/TransmittableThreadLocal.java +++ b/src/main/java/com/alibaba/ttl/TransmittableThreadLocal.java @@ -227,7 +227,8 @@ private void removeThisFromHolder() { } private static void doExecuteCallback(boolean isBefore) { - for (TransmittableThreadLocal threadLocal : holder.get().keySet()) { + WeakHashMap, ?> ttlInstances = new WeakHashMap, Object>(holder.get()); + for (TransmittableThreadLocal threadLocal : ttlInstances.keySet()) { try { if (isBefore) threadLocal.beforeExecute(); else threadLocal.afterExecute();