当前位置:网站首页>Keepalivetime=0 description of ThreadPoolExecutor
Keepalivetime=0 description of ThreadPoolExecutor
2022-07-25 02:09:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
As the title , Here's the picture , explain ThreadPoolExecutor Of keepAliveTime=0.
The above is from 《 The art of concurrent programming 》 A Book , The book has the following description :
“ “ When the number of threads in the thread pool is greater than corePoolSize when ,keepAliveTime The maximum time to wait for new tasks for redundant idle threads , After this time, the redundant threads will be terminated . Here is the keepAliveTime Set to 0L, It means superfluous The idle thread of will be terminated immediately .”
A lot of blog materials on the Internet say 0 Indicates that the thread survives permanently when it is idle . It's not accurate .
Attach verification code :
public static void main(String[] args) throws InterruptedException {
// Created a thread pool
ThreadPoolExecutor executor = new ThreadPoolExecutor(1,
2,
0, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(1));
for (int i = 0; i < 3; i++) {
executor.execute(new DemoTask(i));
}
while (true) {
System.out.println(" Bus number :" + executor.getPoolSize() + ", Number of currently active threads :" + executor.getActiveCount());
TimeUnit.SECONDS.sleep(1);
}
}
static class DemoTask implements Runnable {
int num;
public DemoTask(int i) {
this.num = i;
}
@Override
public void run() {
System.out.println("num=" + num + " Thread = " + Thread.currentThread().getName());
if (num >= 1) {
try {
TimeUnit.SECONDS.sleep(1);
System.out.println("num=" + num + " sleep 1 s end ");
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
try {
TimeUnit.SECONDS.sleep(3);
System.out.println("num=" + num + " sleep 3 s end ");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}Print the results :
num=2 Thread = pool-1-thread-2
Bus number :2, Number of currently active threads :2
num=0 Thread = pool-1-thread-1
num=2 sleep 1 s end
num=1 Thread = pool-1-thread-2
Bus number :2, Number of currently active threads :2
nuPublisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/120971.html Link to the original text :https://javaforall.cn
边栏推荐
- These 11 chrome artifacts are extremely cool to use
- Open source demo | release of open source example of arcall applet
- Server performance monitoring
- Hcip - BGP - border gateway protocol
- "I gave up programming and wrote a 1.3 million word hard science fiction."
- Deep understanding of string class
- Green low-carbon Tianyi cloud, a new engine of digital economy!
- Easy to master SSO single sign on, see this article
- [summer daily question] Luogu P7550 [coci2020-2021 6] bold
- Detailed explanation of the principles and differences between static pages and dynamic pages
猜你喜欢

Talk about what's going on with C # backstage GC?

How to obtain workers' coats and helmets in stray? How to obtain workers' helmets

Alibaba cloud released the white paper "upgrade - standardization of data warehouse upgrade delivery"

Cloud native platform, let edge applications play out!

Redis learning notes (2) - power node of station B

Interpretation of video generation paper of fed shot video to video (neurips 2019)

Example demonstration of "uncover the secrets of asp.net core 6 framework" [02]: application development based on routing, MVC and grpc

Boutique solution | Haitai cloud password application service solution to create secure and compliant Cloud Applications

Academicians said: researchers should also support their families. They can only do short-term and fast research if they are not promoted

What are the important trends revealed by the release of "operator data viability index"?
随机推荐
How to upload files to the server
Example demonstration of "uncover the secrets of asp.net core 6 framework" [02]: application development based on routing, MVC and grpc
MySQL advanced (13) command line export import database
What do growth enterprises need most to build a data-driven organization?
Thinkphp5.0.24 deserialization chain analysis
Win10 configuring CUDA and cudnn
VRRP virtual redundancy protocol configuration
Agreement on sharing agricultural scientific data in China
Full analysis of new functions of report design tool FastReport online designer v2022.1
Simulate the implementation of strstr
Boutique solution | Haitai cloud password application service solution to create secure and compliant Cloud Applications
Jsonp solves cross domain plug-ins (JS, TS)
How MySQL 8.0 based on TRX_ Id find the statement of the whole transaction
[hero planet July training leetcode problem solving daily] 20th BST
Fraud detection using CSP
Plug ins QRcode and ityped
Mongodb security cluster construction
BMW I3 based on clar architecture is not a simple "oil to electricity" product
Yunyuanyuan (VIII) | Devops in depth Devops
JVM Foundation