In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use java object pool". In daily operation, I believe many people have doubts about how to use java object pool. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use java object pool". Next, please follow the editor to study!
Description
1. Create a factory class, inherit or implement the basic interface.
By inheriting BaseGenericObjectPool or implementing the basic interface PooledObjectFactory, and rewriting the methods of creating, destroying, verifying, activating, and passivating objects according to business requirements, most of them are connection closing, empty, and so on.
2. Create a pool and inherit GenericObjectPool.
By inheriting GenericObjectPool or implementing the basic interface ObjectPool, it is recommended to use the former, which provides us with a mechanism for detecting the expulsion of idle objects (that is, destroying objects that have not been used for a long time in the idle queue to reduce memory footprint), as well as providing basic information about many objects, such as the last time the object was used, whether it is checked before using the object, and so on.
3. Create pool-related configurations
To add configuration control to the thread pool by inheriting GenericObjectPoolConfig or BaseObjectPoolConfig, it is recommended to use the former, which implements the basic method for us and only needs to add the attributes we need.
4. Create a wrapper class
That is, for the objects that exist in the object pool, many basic properties are added to the actual objects to make it easy to understand the real-time state of the objects in the object pool.
Example
Private volatile int maxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;private volatile int minIdle = GenericObjectPoolConfig.DEFAULT_MIN_IDLE;public static final int DEFAULT_MAX_IDLE = 8 × public static final int DEFAULT_MIN_IDLE = 0; at this point, the study of "how to use the java object pool" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.