Scopes

A very neat feature of the CDI is to handle the scope life cycle for you. Concretely, you decorate your beans with @ApplicationScoped and @RequestScoped, and the life of the bean is either bound to the application (it is a singleton) or the request duration (which means you can have as many different instances as you have concurrent requests).

The scope implementation is called context, and the context is mainly responsible for looking up in the right contextual instance or creating it. An application scoped instance will be looked up in a single map shared by the entire application. However, a request scoped instance will also be looked up in ThreadLocal associated with the request life cycle through ServletRequestListener.

The implications ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.