Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed locking from Adjust singleton creation #404

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

toby78
Copy link

@toby78 toby78 commented Dec 10, 2019

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.

… a time - so every other thread will need to wait.
… a time - so every other thread will need to wait.
… a time - so every other thread will need to wait

- increased version to 4.19.1
@nonelse
Copy link
Member

nonelse commented Dec 10, 2019

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;
    }

…t a time - so every other thread will need to wait

- increased version to 4.19.1
@toby78
Copy link
Author

toby78 commented Dec 13, 2019

PR updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants