Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2019 Jan Beernink and Arjan Tijms
About this chapter
Cite this chapter
Beernink, J., Tijms, A. (2019). Scopes and Contexts. In: Pro CDI 2 in Java EE 8. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-4363-3_4
Download citation
DOI: https://doi.org/10.1007/978-1-4842-4363-3_4
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-4362-6
Online ISBN: 978-1-4842-4363-3
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)