- 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設備驅動開發詳解(第2版)
- Cybersecurity:Attack and Defense Strategies
- Ansible權威指南
- BPEL and Java Cookbook
- Learn Helm
- Ubuntu Linux操作系統
- Windows Phone 7.5 Data Cookbook
- 嵌入式Linux驅動程序和系統開發實例精講
- Linux操作系統應用編程
- 高性能Linux服務器構建實戰:系統安全、故障排查、自動化運維與集群架構
- 網絡操作系統管理與應用(第三版)
- Social Data Visualization with HTML5 and JavaScript
- Python UNIX和Linux系統管理指南
- 精解Windows 10
- Linux指令從初學到精通