当前位置:网站首页>Pooling idea: string constant pool, thread pool, database connection pool
Pooling idea: string constant pool, thread pool, database connection pool
2022-07-03 22:07:00 【ZJH'blog】
Pool thought
Resources are reused , Return after use , Save a lot of time and resources wasted in building and destroying , There are still a lot of resources for establishment and destruction
String constant pool
Constant pools are independent of stacks and heaps , The following two creation methods are different
1, Save the contents of constant pool directly
String s1 = “ Save directly ”
2,new String Save indirectly
String s2 = new String(“ Save indirectly ”)
difference :
- Save directly , No matter how many are created, they are the same
- Indirect saving actually saves the address value , Point to thread pool , This method produces two objects ; If you save indirectly for many times , for example :
String s3 = new String(“ Save indirectly ”)
String s4 = new String(“ Save indirectly ”)
String s5 = new String(“ Save indirectly ”)
In fact, only one is created in the constant pool " Save indirectly " The object of , The reference object creates 3 Time
Thread pool
Advantages compared with tradition
- Traditional thread implementation methods include thread creation Thread to destroy Time for , Threads can be reused , So the thread pool is introduced , Create and destroy threads Change it to Return after use , Not destroyed , Reuse resources , Improve thread utilization , Improve the response speed of the program
- Easy to manage Thread objects in a unified way
- You can control the maximum concurrency
Thread pool model —— Bank
Counter window : Threads , Without destroying
Waiting area : Waiting in line
When the window is not enough : Add threads
When there are no seats in the waiting area : Refusal strategy —— Report an exception or give it to a thread to go left
There are too many free windows : Reduce threads
Thread pool creation
JUC The concurrency toolkit provides ThreadPoolExecutor Creating a thread pool ,ThreadPoolExecutor Yes 8 Parameters , Respectively :
- corePoolSize: Number of core threads —— The number of counter windows that never close
- maximumPoolSize: Maximum number of threads —— The maximum number of windows
- keepAliveTime: Thread lifetime —— How long does it take for a non core thread to be destroyed without receiving a task —— You need to set the unit unit
- unit:TimeUnit.SECONDS or TimeUnit.MICROSECONDS You can wait
- BlockingQueue : Waiting in line ,new ArrayBlockingQueue<>(capacity:10) here capacity The value of the set 10
- ThreadFactory: Thread factory —— No need to create , Call directly Executors.defaultThreadFactory()
- RejectedExecutionHandler: Refusal strategy ——new ThreadPoolExecutor.AbortPolicy() The handler of the rejected task , Throw a RejectedExecutionException
After creating it, use ExecutorService Class object to receive , Then you can directly call
for example : utilize lambda expression
for(){
executorService.execute( ()->{ Thread business logic } );
}// The thread pool will automatically adjust the current number of threads
executorService.shutdown();// Close thread pool
Reference resources :

Database connection pool
advantage
- Resource reuse
- Faster system response
- New means of resource allocation
- Unified connection management , Avoid database connection leaks
Excellent open source database connection pool agent
(1)DBCP yes Apache Database connection pool provided .tomcat The server comes with dbcp Database connection pool . Speed is relative to c3p0 Faster , But because of its own existence BUG,Hibernate3 Support is no longer available .
(2)C3P0 It is a database connection pool provided by an open source organization , Relatively slow , Stability is OK ,hibernate Official recommendation .
(3)Proxool yes sourceforge The next open source project database connection pool , It has the function of monitoring connection pool status , More stable c3p0 almost .
(4)BoneCP Is a database connection pool provided by an open source organization , Fast .
(5)Druid It is the database connection pool provided by Ali , It's said to be a collection DBCP 、C3P0 、Proxool All in one database connection pool , But the speed is not sure if there is BoneCP fast .
边栏推荐
- Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files
- 抓包整理外篇——————autoResponder、composer 、statistics [ 三]
- [SRS] build a specified version of SRS
- Station B, dark horse programmer, employee management system, access conflict related (there is an unhandled exception at 0x00007ff633a4c54d (in employee management system.Exe): 0xc0000005: read locat
- Imitation Netease cloud music applet
- js demo 计算本年度还剩下多少天
- Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
- Remember the experience of automatically jumping to spinach station when the home page was tampered with
- Plug - in Oil Monkey
- The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
猜你喜欢

UC Berkeley proposes a multitask framework slip

Preliminary analysis of smart microwave radar module

The post-90s resigned and started a business, saying they would kill cloud database

Tidb's initial experience of ticdc6.0

On my first day at work, this API timeout optimization put me down!

Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)

2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units

Morning flowers and evening flowers

IPhone development swift foundation 09 assets

使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
随机推荐
Global and Chinese market of telematics boxes 2022-2028: Research Report on technology, participants, trends, market size and share
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
90 後,辭職創業,說要卷死雲數據庫
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
内存分析器 (MAT)
treevalue——Master Nested Data Like Tensor
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
MySQL——JDBC
Correlation
QGIS grid processing DEM data reclassification
What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
Global and Chinese market of wall mounted kiosks 2022-2028: Research Report on technology, participants, trends, market size and share
Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
Global and Chinese market of gallic acid 2022-2028: Research Report on technology, participants, trends, market size and share
Mysql database - Advanced SQL statement (I)
Why use pycharm to run the use case successfully but cannot exit?
