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

RouteManager中的单例模式写的应该是不对的 #63

Open
aolphn opened this issue Aug 14, 2017 · 1 comment
Open

RouteManager中的单例模式写的应该是不对的 #63

aolphn opened this issue Aug 14, 2017 · 1 comment

Comments

@aolphn
Copy link

aolphn commented Aug 14, 2017

private static RouteManager sInstance;//这种写法静态变量应该用volatile修饰,不然指令重排序可能导致其他线程获取到错误的单例,可以看一下这里说明:https://my.oschina.net/u/2250599/blog/412827
public static RouteManager getInstance(boolean asyncLoadRoute) {
        if (null == sInstance) {
            synchronized (RouteManager.class) {
                if (null == sInstance) {
                    sInstance = new RouteManager(asyncLoadRoute);
                }
            }
        }
        return sInstance;
 }
@shaobin0604
Copy link

@aolphn 👍

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

No branches or pull requests

2 participants