Make mExtraData in ContextChain synchronized
@@ -13,6 +13,7 @@ import com.facebook.common.internal.Objects;
import com.facebook.common.internal.Preconditions;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
/**
@@ -45,6 +46,8 @@ public class ContextChain implements Parcelable {
private @Nullable String mSerializedString;
+ private static boolean sUseConcurrentHashMap = false;
+
public ContextChain(
final String tag,
final String name,
@@ -60,13 +63,21 @@ public class ContextChain implements Parcelable {
parentExtraData = parent.getExtraData();
}
if (parentExtraData != null) {
+ if (sUseConcurrentHashMap) {
+ mExtraData = new ConcurrentHashMap<>(parentExtraData);
+ } else {
mExtraData = new HashMap<>(parentExtraData);
}
+ }
if (extraData != null) {
if (mExtraData == null) {
+ if (sUseConcurrentHashMap) {
+ mExtraData = new ConcurrentHashMap<>();
+ } else {
mExtraData = new HashMap<>();
}
+ }
mExtraData.putAll(extraData);
}
}
@@ -82,6 +93,10 @@ public class ContextChain implements Parcelable {
mParent = in.readParcelable(ContextChain.class.getClassLoader());
}
+ public static void setUseConcurrentHashMap(boolean useConcurrentHashMap) {
+ sUseConcurrentHashMap = useConcurrentHashMap;
+ }
+
public String getName() {
return mName;
}
@@ -115,8 +130,12 @@ public class ContextChain implements Parcelable {
public void putObjectExtra(String key, Object value) {
if (mExtraData == null) {
+ if (sUseConcurrentHashMap) {
+ mExtraData = new ConcurrentHashMap<>();
+ } else {
mExtraData = new HashMap<>();
}
+ }
mExtraData.put(key, value);
}
