Skip to main content

Scopes and Contexts

  • Chapter
  • First Online:
Pro CDI 2 in Java EE 8
  • 552 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Jan Beernink and Arjan Tijms

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

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

Publish with us

Policies and ethics