Question

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!

Was it helpful?

Solution

I don't have a direct reference to the spec that absolutely guarantees this, but @PostConstruct should be thread safe.

The CDI runtime is fully in charge of creating beans and will only create one instance for a given scope. @PostConstruct runs before the bean is accessible in such a scope or via injection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top