- Java EE 8 High Performance
- Romain Manni Bucau
- 204字
- 2021-06-30 19:14:27
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 on the performance are quite immediate:
- The context setup can be pricey (depending on the scope) and can add some overhead that you may not require. In fact, if you have no @RequestScoped bean, you don't need the ServletRequestListener instance (even if not very expensive).
- Recreating your bean every time the context needs it will trigger the process we saw in the previous part and the life cycle hooks of the bean (@PostConstruct and @PreDestroy).
- 操作系統實用教程(Linux版)
- Mastering vRealize Operations Manager(Second Edition)
- Learning OpenDaylight
- 嵌入式Linux開發技術
- 阿里云數字新基建系列:云原生操作系統Kubernetes
- Implementing Azure DevOps Solutions
- 異質結原理與器件
- Alfresco 4 Enterprise Content Management Implementation
- Moodle 3.x Teaching Techniques(Third Edition)
- Python基礎教程(第3版)
- Docker+Kubernetes應用開發與快速上云
- Windows Server 2012網絡操作系統項目教程(第4版)
- iOS 8開發指南
- Windows Server 2008組網技術與實訓(第3版)
- Linux從入門到精通(視頻教學版)