简体   繁体   中英

Questions about @PostConstruct

I have a couple questions about @PostConstruct in Spring.

  1. @PostConstruct is thread safe?
  2. Does this open a new thread for the init method or how it works?

I will be grateful for the answers)

  1. Yes, Spring calls @PostConstruct marked methods the object before it gets available to the application (Before injection). This is a part of bean creation.

  2. No. Spring creates an internal structure called "bean definition" during the application context initialization. Its a meta data about the bean. If the bean has "post-construct" method spring knows this and calls the relevant method during the bean creation.

@PostConstruct is thread safe. It only runs once after the bean created in the whole lifecycle of the bean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM