Does anyone know whether the initialization of instance fields within a method annotated with PostConstruct is considered to be thread safe? I am not quite sure if i have to make my fields of my ApplicationScoped bean volatile or not so other threads can really see the values…
Thanks for any hints or answers!
I don’t have a direct reference to the spec that absolutely guarantees this, but
@PostConstructshould be thread safe.The CDI runtime is fully in charge of creating beans and will only create one instance for a given scope.
@PostConstructruns before the bean is accessible in such a scope or via injection.