This repository was archived by the owner on Mar 3, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-15
lines changed
connectionclass/src/main/java/com/facebook/network/connectionclass Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -64,19 +64,17 @@ public class ConnectionClassManager {
6464 static final long BANDWIDTH_LOWER_BOUND = 10 ;
6565
6666 // Singleton.
67- @ Nullable
68- private static ConnectionClassManager sInstance ;
67+ private static class ConnectionClassManagerHolder {
68+ public static final ConnectionClassManager instance = new ConnectionClassManager ();
69+ }
6970
7071 /**
7172 * Retrieval method for the DownloadBandwidthManager singleton.
7273 * @return The singleton instance of DownloadBandwidthManager.
7374 */
7475 @ Nonnull
7576 public static ConnectionClassManager getInstance () {
76- if (sInstance == null ) {
77- sInstance = new ConnectionClassManager ();
78- }
79- return sInstance ;
77+ return ConnectionClassManagerHolder .instance ;
8078 }
8179
8280 // Force constructor to be private.
Original file line number Diff line number Diff line change @@ -41,20 +41,19 @@ public class DeviceBandwidthSampler {
4141
4242 private long mLastTimeReading ;
4343
44- // Make BandwidthTimerManager a singleton.
45- @ Nullable
46- private static DeviceBandwidthSampler sInstance ;
44+ // Singleton.
45+ private static class DeviceBandwidthSamplerHolder {
46+ public static final DeviceBandwidthSampler instance =
47+ new DeviceBandwidthSampler (ConnectionClassManager .getInstance ());
48+ }
4749
4850 /**
49- * Retrieval method for the BandwidthTimerManager singleton.
50- * @return The singleton instance of BandwidthTimerManager .
51+ * Retrieval method for the DeviceBandwidthSampler singleton.
52+ * @return The singleton instance of DeviceBandwidthSampler .
5153 */
5254 @ Nonnull
5355 public static DeviceBandwidthSampler getInstance () {
54- if (sInstance == null ) {
55- sInstance = new DeviceBandwidthSampler (ConnectionClassManager .getInstance ());
56- }
57- return sInstance ;
56+ return DeviceBandwidthSamplerHolder .instance ;
5857 }
5958
6059 private DeviceBandwidthSampler (
You can’t perform that action at this time.
0 commit comments