diff --git a/ttl-core/src/main/java/com/alibaba/crr/composite/CompositeCrrTransmit.java b/ttl-core/src/main/java/com/alibaba/crr/composite/CompositeCrrTransmit.java index 8e82bc9a7..368347224 100644 --- a/ttl-core/src/main/java/com/alibaba/crr/composite/CompositeCrrTransmit.java +++ b/ttl-core/src/main/java/com/alibaba/crr/composite/CompositeCrrTransmit.java @@ -10,6 +10,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import static com.alibaba.ttl3.internal.util.Utils.newHashMap; + /** * {@link CompositeCrrTransmit} transmit all {@link CrrTransmit} * registered by {@link #registerCrrTransmit(CrrTransmit)}. @@ -41,7 +43,7 @@ public CompositeCrrTransmit(CompositeCrrTransmitCallback callback) { */ @NonNull public Capture capture() { - final HashMap, Object> crrTransmit2Value = new HashMap<>(registeredCrrTransmitSet.size()); + final HashMap, Object> crrTransmit2Value = newHashMap(registeredCrrTransmitSet.size()); for (CrrTransmit crrTransmit : registeredCrrTransmitSet) { try { crrTransmit2Value.put(crrTransmit, crrTransmit.capture()); @@ -68,7 +70,7 @@ public Backup replay(@NonNull Capture captured) { final Object data = callback.beforeReplay(); final Snapshot capturedSnapshot = (Snapshot) captured; - final HashMap, Object> crrTransmit2Value = new HashMap<>(capturedSnapshot.crrTransmit2Value.size()); + final HashMap, Object> crrTransmit2Value = newHashMap(capturedSnapshot.crrTransmit2Value.size()); for (Map.Entry, Object> entry : capturedSnapshot.crrTransmit2Value.entrySet()) { CrrTransmit crrTransmit = entry.getKey(); try { @@ -105,7 +107,7 @@ public Backup replay(@NonNull Capture captured) { public Backup clear() { final Object data = callback.beforeReplay(); - final HashMap, Object> crrTransmit2Value = new HashMap<>(registeredCrrTransmitSet.size()); + final HashMap, Object> crrTransmit2Value = newHashMap(registeredCrrTransmitSet.size()); for (CrrTransmit crrTransmit : registeredCrrTransmitSet) { try { crrTransmit2Value.put(crrTransmit, crrTransmit.clear()); diff --git a/ttl-core/src/main/java/com/alibaba/ttl3/TransmittableThreadLocal.java b/ttl-core/src/main/java/com/alibaba/ttl3/TransmittableThreadLocal.java index ac7a70ba0..7269a7aff 100644 --- a/ttl-core/src/main/java/com/alibaba/ttl3/TransmittableThreadLocal.java +++ b/ttl-core/src/main/java/com/alibaba/ttl3/TransmittableThreadLocal.java @@ -12,6 +12,8 @@ import java.util.WeakHashMap; import java.util.function.Supplier; +import static com.alibaba.ttl3.internal.util.Utils.newHashMap; + /** * {@link TransmittableThreadLocal}({@code TTL}) can transmit the value from the thread of submitting task * to the thread of executing task even using thread pooling components. @@ -330,7 +332,7 @@ private static class TtlTransmittee implements Transmittee, Object> capture() { - final HashMap, Object> ttl2Value = new HashMap<>(holder.get().size()); + final HashMap, Object> ttl2Value = newHashMap(holder.get().size()); for (TransmittableThreadLocal threadLocal : holder.get().keySet()) { ttl2Value.put(threadLocal, threadLocal.getTransmitteeValue()); } @@ -340,7 +342,7 @@ public HashMap, Object> capture() { @NonNull @Override public HashMap, Object> replay(@NonNull HashMap, Object> captured) { - final HashMap, Object> backup = new HashMap<>(holder.get().size()); + final HashMap, Object> backup = newHashMap(holder.get().size()); for (final Iterator> iterator = holder.get().keySet().iterator(); iterator.hasNext(); ) { TransmittableThreadLocal threadLocal = iterator.next(); @@ -365,7 +367,7 @@ public HashMap, Object> replay(@NonNull HashMap @NonNull @Override public HashMap, Object> clear() { - return replay(new HashMap<>(0)); + return replay(newHashMap(0)); } @Override diff --git a/ttl-core/src/main/java/com/alibaba/ttl3/transmitter/ThreadLocalTransmitRegistry.java b/ttl-core/src/main/java/com/alibaba/ttl3/transmitter/ThreadLocalTransmitRegistry.java index 65a0c929b..5beee5806 100644 --- a/ttl-core/src/main/java/com/alibaba/ttl3/transmitter/ThreadLocalTransmitRegistry.java +++ b/ttl-core/src/main/java/com/alibaba/ttl3/transmitter/ThreadLocalTransmitRegistry.java @@ -9,6 +9,8 @@ import java.util.WeakHashMap; import java.util.logging.Logger; +import static com.alibaba.ttl3.internal.util.Utils.newHashMap; + /** * {@code ThreadLocalTransmitRegistry}, {@code ThreadLocal} transmit integration. *

@@ -142,7 +144,7 @@ private static class ThreadLocalTransmittee implements Transmittee, Object> capture() { - final HashMap, Object> threadLocal2Value = new HashMap<>(threadLocalHolder.size()); + final HashMap, Object> threadLocal2Value = newHashMap(threadLocalHolder.size()); for (Map.Entry, TtlCopier> entry : threadLocalHolder.entrySet()) { final ThreadLocal threadLocal = entry.getKey(); final TtlCopier copier = entry.getValue(); @@ -155,7 +157,7 @@ public HashMap, Object> capture() { @NonNull @Override public HashMap, Object> replay(@NonNull HashMap, Object> captured) { - final HashMap, Object> backup = new HashMap<>(captured.size()); + final HashMap, Object> backup = newHashMap(captured.size()); for (Map.Entry, Object> entry : captured.entrySet()) { final ThreadLocal threadLocal = entry.getKey(); @@ -172,7 +174,7 @@ public HashMap, Object> replay(@NonNull HashMap, Object> clear() { - final HashMap, Object> threadLocal2Value = new HashMap<>(threadLocalHolder.size()); + final HashMap, Object> threadLocal2Value = newHashMap(threadLocalHolder.size()); for (Map.Entry, TtlCopier> entry : threadLocalHolder.entrySet()) { final ThreadLocal threadLocal = entry.getKey();