android_sdk
android_sdk copied to clipboard
removed locking from Adjust singleton creation
Removed locking from Adjust singleton creation. Create instance immediately when the class is loaded or initialized (Android ClassLoader). It will be 100% thread safe and the object instance will already be available before any thread accesses it. If class should not be created, disable the SDK instead.
While I agree that removing the synchronized
removes some unnecessary locks, I'm not sure changing it to early initialization is worth it.
What it could be changed to, is something like the double checked locking, making it looking to something like this:
private volatile AdjustInstance defaultInstance;
public static void AdjustInstance getDefaultInstance()
{
if (defaultInstance == null) {
synchronized (Adjust.class) {
if (defaultInstance == null) {
defaultInstance = new AdjustInstance();
}
}
}
return defaultInstance;
}
PR updated