File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
src/main/java/com/concurrent/threadpool Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .concurrent .threadpool ;
2+
3+ import java .util .concurrent .ExecutorService ;
4+ import java .util .concurrent .LinkedBlockingQueue ;
5+ import java .util .concurrent .ThreadPoolExecutor ;
6+ import java .util .concurrent .TimeUnit ;
7+
8+
9+
10+ public class ThreadNum {
11+
12+
13+
14+ // private static final ExecutorService MY_EXECUTOR = Executors.newFixedThreadPool(5);
15+
16+ /**
17+ * 自定义ThreadFactory
18+ * 自定义线程池
19+ *
20+ */
21+ private static final ExecutorService THREAD_POOL_EXECUTOR = new ThreadPoolExecutor (
22+ 5 , 20 ,
23+ 2 , TimeUnit .SECONDS ,
24+ new LinkedBlockingQueue <>(1000 ),
25+ ThreadFactoryImpl .builder ().threadName ("thead-my-" ).build ());
26+
27+
28+
29+ public static void main (String [] args ) {
30+ THREAD_POOL_EXECUTOR .execute (()-> System .out .println (Thread .currentThread ().getName ()+ ":first thread." ));
31+ THREAD_POOL_EXECUTOR .execute (()-> System .out .println (Thread .currentThread ().getName ()+ ":second thread." ));
32+ THREAD_POOL_EXECUTOR .shutdown ();
33+ }
34+
35+
36+
37+
38+ }
You can’t perform that action at this time.
0 commit comments