参考:https://blog.csdn.net/lihenair/article/details/61913542
在ActivityThread中看到如下的用法:
@GuardedBy("mResourcesManager")
final ArrayMap<String, WeakReference<LoadedApk>> mPackages = new ArrayMap<>();
@GuardedBy("mResourcesManager")
final ArrayMap<String, WeakReference<LoadedApk>> mResourcePackages = new ArrayMap<>();
@GuardedBy("mResourcesManager")
final ArrayList<ActivityClientRecord> mRelaunchingActivities = new ArrayList<>();
@GuardedBy("mResourcesManager")
Configuration mPendingConfiguration = null;
@GuardedBy("mResourcesManager")
int mLifecycleSeq = 0;
private final ResourcesManager mResourcesManager;
对这些成员变量加上了注解词@GuardedBy("mResourcesManager")。
根据参考的文章,这个是一个同步锁,只有在线程持有mResourcesManager对象锁时,才能使用这写变量。
如:
private int getLifecycleSeq() {
synchronized (mResourcesManager) {
return mLifecycleSeq++;
}
}