Coder Social home page Coder Social logo

Comments (6)

zhi1ong avatar zhi1ong commented on May 2, 2024

initInterceptor只会调用一次,这个是由整个SDK的初始化流程控制的,SDK的初始化是有锁的。

from arouter.

mjjde avatar mjjde commented on May 2, 2024

这段代码里面是由线程池执行的,对里面的TreeMap的读取和对ArrayList的写入不会造成问题吗?

from arouter.

zhi1ong avatar zhi1ong commented on May 2, 2024

逻辑上不会,拦截器的初始化确实是在线程池中异步的,但是第一次路由调用的时候,如果拦截器没有初始化完的话,路由请求会等待拦截器初始化结束, checkInterceptorsInitStatus() ,不会同时读写的。

from arouter.

mjjde avatar mjjde commented on May 2, 2024

我的意思是

// Cache interceptor
private static Map<Integer, Class<? extends IInterceptor>> interceptorsIndex = new TreeMap<>();
private static List<IInterceptor> interceptors = new ArrayList<>();

是否需要换成线程安全的Map和List

异步里面如果一个线程在初始化最后一个拦截器 而另一个线程不进入for循序就去执行下面的
interceptorHasInit = true;

这样的话checkInterceptorsInitStatus()是否就失效了呢

from arouter.

zhi1ong avatar zhi1ong commented on May 2, 2024
initInterceptor只会调用一次,这个是由整个SDK的初始化流程控制的,SDK的初始化是有锁的。

如果不考虑上下文的话,单看这段代码是有线程安全风险的,但是首先这个方法不会被调用多次,他只会被调用一次,是通过ARouter.init()里面的锁来控制的,这就保证了interceptorHasInit不会被多次修改,其次这个List的读取是一定在写入完成之后,是由interceptorHasInit这个标志位来控制的,以上,这里应该是没有问题的。

from arouter.

mjjde avatar mjjde commented on May 2, 2024

恩 好的 谢谢你的解答 ~

from arouter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.