- 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).
- Windows Server 2019 Cookbook
- Windows Vista基礎與應用精品教程
- 零起點學Linux系統(tǒng)管理
- 鴻蒙生態(tài):開啟萬物互聯(lián)的智慧新時代
- 新手易學:系統(tǒng)安裝與重裝
- 數(shù)據(jù)中心系統(tǒng)工程及應用
- 無蘋果不生活 The New iPad隨身寶典
- AutoCAD 2014中文版從入門到精通
- Hands-On UX Design for Developers
- 跟老男孩學Linux運維:Shell編程實戰(zhàn)
- HTML5 Enterprise Application Development
- Less Web Development Essentials
- Android NDK Beginner's Guide
- BuddyPress Theme Development
- Learning Joomla! 3 Extension Development(Third Edition)