Showing
2 changed files
with
40 additions
and
3 deletions
@@ -11,8 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -11,8 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
12 | 12 | ||
13 | import java.util.List; | 13 | import java.util.List; |
14 | -import java.util.concurrent.ExecutorService; | ||
15 | -import java.util.concurrent.Executors; | 14 | +import java.util.concurrent.*; |
16 | 15 | ||
17 | /** | 16 | /** |
18 | * Created by chenchao on 2018/10/8. | 17 | * Created by chenchao on 2018/10/8. |
@@ -22,7 +21,7 @@ public class InBoxFacade { | @@ -22,7 +21,7 @@ public class InBoxFacade { | ||
22 | 21 | ||
23 | private final Logger logger = LoggerFactory.getLogger(getClass()); | 22 | private final Logger logger = LoggerFactory.getLogger(getClass()); |
24 | 23 | ||
25 | - private ExecutorService executorService = Executors.newFixedThreadPool(30); | 24 | + private ExecutorService executorService = new ThreadPoolExecutor(10, 60, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(30), new InBoxThreadFactory()); |
26 | 25 | ||
27 | @Autowired | 26 | @Autowired |
28 | private InBoxSDK inBoxSDK; | 27 | private InBoxSDK inBoxSDK; |
1 | +package com.yohoufo.order.service.proxy; | ||
2 | + | ||
3 | +import java.util.concurrent.ThreadFactory; | ||
4 | +import java.util.concurrent.atomic.AtomicInteger; | ||
5 | + | ||
6 | +/** | ||
7 | + * 自定义java api线程池内工作线程工厂 | ||
8 | + * 指定生成线程名称:pool-javaApi-thread-[num] | ||
9 | + */ | ||
10 | +public class InBoxThreadFactory implements ThreadFactory { | ||
11 | + | ||
12 | + private static final AtomicInteger poolNumber = new AtomicInteger(1); | ||
13 | + private final AtomicInteger threadNumber = new AtomicInteger(1); | ||
14 | + private final String namePrefix; | ||
15 | + private final ThreadGroup group; | ||
16 | + | ||
17 | + public InBoxThreadFactory() { | ||
18 | + SecurityManager s = System.getSecurityManager(); | ||
19 | + group = (s != null) ? s.getThreadGroup() : | ||
20 | + Thread.currentThread().getThreadGroup(); | ||
21 | + namePrefix = "pool-inboxFacade-processor-" + | ||
22 | + poolNumber.getAndIncrement() + | ||
23 | + "-thread-"; | ||
24 | + } | ||
25 | + | ||
26 | + | ||
27 | + @Override | ||
28 | + public Thread newThread(Runnable r) { | ||
29 | + Thread t = new Thread(group, r, | ||
30 | + namePrefix + threadNumber.getAndIncrement(), | ||
31 | + 0); | ||
32 | + if (t.isDaemon()) | ||
33 | + t.setDaemon(true); | ||
34 | + if (t.getPriority() != Thread.NORM_PRIORITY) | ||
35 | + t.setPriority(Thread.NORM_PRIORITY); | ||
36 | + return t; | ||
37 | + } | ||
38 | +} |
-
Please register or login to post a comment