rexxar-android icon indicating copy to clipboard operation
rexxar-android copied to clipboard

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

Open aolphn opened this issue 7 years ago • 1 comments

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

aolphn avatar Aug 14 '17 06:08 aolphn

@aolphn 👍

shaobin0604 avatar Sep 28 '18 08:09 shaobin0604