DCL is broken and should not be used.

Use the acceptable instance holder pattern as a replacement.

Change-Id: I0164b8c17db4e6e15aee5a862fa8e625a9b1bbf4
This commit is contained in:
Pascal Muetschard
2022-08-17 17:40:30 +02:00
parent fbaaa44ccf
commit ab0cbeffdf
2 changed files with 6 additions and 10 deletions

View File

@@ -9,3 +9,4 @@ android.net.rtp.AudioGroup
android.net.rtp.AudioStream
android.net.rtp.RtpStream
java.util.concurrent.ThreadLocalRandom
com.android.internal.jank.InteractionJankMonitor$InstanceHolder

View File

@@ -292,7 +292,10 @@ public class InteractionJankMonitor {
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SHADE_CLEAR_ALL,
};
private static volatile InteractionJankMonitor sInstance;
private static class InstanceHolder {
public static final InteractionJankMonitor INSTANCE =
new InteractionJankMonitor(new HandlerThread(DEFAULT_WORKER_NAME));
}
private final DeviceConfig.OnPropertiesChangedListener mPropertiesChangedListener =
this::updateProperties;
@@ -384,15 +387,7 @@ public class InteractionJankMonitor {
* @return instance of InteractionJankMonitor
*/
public static InteractionJankMonitor getInstance() {
// Use DCL here since this method might be invoked very often.
if (sInstance == null) {
synchronized (InteractionJankMonitor.class) {
if (sInstance == null) {
sInstance = new InteractionJankMonitor(new HandlerThread(DEFAULT_WORKER_NAME));
}
}
}
return sInstance;
return InstanceHolder.INSTANCE;
}
/**