- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCachedThreadPool.java
More file actions
Latest commit
28 lines (16 loc) · 730 Bytes
/
Copy pathCachedThreadPool.java
File metadata and controls
28 lines (16 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
importjava.util.concurrent.ExecutorService;
importjava.util.concurrent.Executors;
publicclassCachedThreadPool {
publicstaticvoidmain(String[] args) {
System.out.println(Thread.currentThread().getName());
//In the cached thread pool it will check if the current threads are busy or not if they are busy only in that
//condition it will create a new thread.
ExecutorServiceexecutorService = Executors.newCachedThreadPool();
for(inti=0;i<100;i++){
Threadthread=newThread(()->{
System.out.println(Thread.currentThread().getName());
});
executorService.execute(thread);
}
}
}