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

Application的onCreate中在子线程使用Router.lazyInit(),同时onCreate的主线程中使用了Router.getService,导致偶现路由跳转页面失败 #73

Open
jiangming8 opened this issue Nov 13, 2019 · 2 comments

Comments

@jiangming8
Copy link

jiangming8 commented Nov 13, 2019

如题,在Application的onCreate方法中,在使用后台线程进行懒加载Router.lazyInit()。同时onCreate的主线程中使用了Router.getService,导致偶现路由跳转页面失败。调试后发现是路由表ServiceLoaderInit类的init方法还没有执行完成,就开始调用了UriAnnotationHandler的performInit方法。

请问这种情况应该怎么处理。

`
public class MApplication extends Application {

public void onCreate() {
       DefaultRootUriHandler rootHandler = new DefaultRootUriHandler(context);
       Router.init(rootHandler);
       // 懒加载后台初始化(可选)
       new AsyncTask<Void, Void, Void>() {
          @Override
          protected Void doInBackground(Void... voids) {
              Router.lazyInit();
              return null;
          }
      }.execute();
     ...
     Router.getService(IHomeMineModule.class, "homemine");
}

}

`

@jzj1993
Copy link
Collaborator

jzj1993 commented Mar 12, 2020

Router.lazyInit()和UriAnnotationHandler中的init都调用了LazyInitHelper,有用synchronized做线程同步处理。理论上来说如果lazyInit还没执行完,主线程会等待lazyInit执行结束再跳转,不会出现跳转失败的情况。

@Spr-Aut
Copy link

Spr-Aut commented Nov 15, 2024

我也遇到了类似的多线程问题,我排查后发现是因为之前LazyInitHelper$performInit里mHasInit=true的赋值时机有问题,应该在完成初始化后再赋值的。在这份提交里已经改掉这个问题了,b0c330a#diff-53c81753048792fee5c631c7a064c36ad5dd41c13a7e49eba94da72f2d12c7d4R51

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

3 participants