Scopes and Contexts

Jan Beernink, Arjan Tijms · Apress eBooks · 2019

Because the CDI container is responsible for the creation and destruction of beans in a CDI-enabled application, it essentially is responsible for the lifecycle of the beans it manages. This means the container should be made aware when it is safe to create and destroy each bean. If a bean is created too late, code depending on that bean may fail. If the bean is destroyed too late, memory may become clogged up with old, obsolete objects, leading to longer garbage collection pauses and eventually out-of-memory errors. Another issue with the lifecycle management of a bean is the sharing of bean instances between different beans. For example, it could be too costly to create multiple instances of a certain bean. A bean could also be mutable, and any changes should be directly visible to all other beans that depend on that bean. If a bean contains or manages any privacy-sensitive data, an application may also want to limit the visibility of this bean to other beans.

Read the paper · More papers on PaperTik