Use a double check in getKey instead of synchronizing every call.
RELNOTES: None.
@@ -22,10 +22,12 @@ import javax.annotation.Nullable;
*/
public abstract class ActionKeyCacher implements ActionAnalysisMetadata {
- @Nullable private String cachedKey = null;
+ @Nullable private volatile String cachedKey = null;
@Override
- public final synchronized String getKey(ActionKeyContext actionKeyContext) {
+ public final String getKey(ActionKeyContext actionKeyContext) {
+ if (cachedKey == null) {
+ synchronized (this) {
if (cachedKey == null) {
try {
Fingerprint fp = new Fingerprint();
@@ -44,6 +46,8 @@ public abstract class ActionKeyCacher implements ActionAnalysisMetadata {
cachedKey = KEY_ERROR;
}
}
+ }
+ }
return cachedKey;
}
