search

Home  >  Q&A  >  body text

java - sprin加载完xml,初始化好bean之后,怎么保证初始化好的bean始终被引用的,也就是说怎么保证不被垃圾回收机制回收

PHPzPHPz2892 days ago369

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:36

    You can simplify spring:

    //简化成下面这样,具体可以去看spring源码
    Map<String, Object> applicationContext

    In the default Singleton mode, after loading the xml, the instantiated object has been referenced by the ApplicationContext and will not be recycled during the spring life cycle

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:34:36

    Initialized beans are maintained in a map, and this map is final修饰,这样map就作为了一个GC ROOT对象,jvm采用的可达性分析算法

    reply
    0
  • Cancelreply