|
1 | 1 | package info.xiaomo.gengine.thread; |
2 | 2 |
|
| 3 | +import lombok.Data; |
| 4 | +import org.simpleframework.xml.Element; |
| 5 | +import org.simpleframework.xml.Root; |
| 6 | + |
3 | 7 | import java.util.concurrent.LinkedBlockingQueue; |
4 | 8 | import java.util.concurrent.ThreadPoolExecutor; |
5 | 9 | import java.util.concurrent.TimeUnit; |
6 | | -import org.simpleframework.xml.Element; |
7 | | -import org.simpleframework.xml.Root; |
8 | 10 |
|
9 | 11 | /** |
10 | 12 | * 线程池配置 |
|
13 | 15 | * 2017-03-30 |
14 | 16 | */ |
15 | 17 | @Root |
| 18 | +@Data |
16 | 19 | public class ThreadPoolExecutorConfig { |
17 | 20 |
|
18 | | - // 线程池名称 |
19 | | - @Element(required = false) |
20 | | - private String name; |
21 | | - |
22 | | - // 核心线程池值 |
23 | | - @Element(required = true) |
24 | | - private int corePoolSize = 20; |
25 | | - |
26 | | - // 线程池最大值 |
27 | | - @Element(required = true) |
28 | | - private int maxPoolSize = 200; |
29 | | - |
30 | | - // 线程池保持活跃时间(秒) |
31 | | - @Element(required = true) |
32 | | - private long keepAliveTime = 30L; |
33 | | - |
34 | | - // 心跳间隔(大于0开启定时监测线程) |
35 | | - @Element(required = false) |
36 | | - private int heart; |
37 | | - |
38 | | - // 缓存命令数 |
39 | | - @Element(required = false) |
40 | | - private int commandSize = 100000; |
41 | | - |
42 | | - public ThreadPoolExecutor newThreadPoolExecutor() throws RuntimeException { |
43 | | - return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, |
44 | | - new LinkedBlockingQueue<>(commandSize), new IoThreadFactory()); |
45 | | - } |
46 | | - |
47 | | - public String getName() { |
48 | | - return name; |
49 | | - } |
50 | | - |
51 | | - public void setName(String name) { |
52 | | - this.name = name; |
53 | | - } |
54 | | - |
55 | | - public int getCorePoolSize() { |
56 | | - return corePoolSize; |
57 | | - } |
58 | | - |
59 | | - @Deprecated |
60 | | - public void setCorePoolSize(int corePoolSize) { |
61 | | - this.corePoolSize = corePoolSize; |
62 | | - } |
63 | | - |
64 | | - public int getMaxPoolSize() { |
65 | | - return maxPoolSize; |
66 | | - } |
67 | | - |
68 | | - @Deprecated |
69 | | - public void setMaxPoolSize(int maxPoolSize) { |
70 | | - this.maxPoolSize = maxPoolSize; |
71 | | - } |
| 21 | + // 线程池名称 |
| 22 | + @Element(required = false) |
| 23 | + private String name; |
72 | 24 |
|
73 | | - public long getKeepAliveTime() { |
74 | | - return keepAliveTime; |
75 | | - } |
| 25 | + // 核心线程池值 |
| 26 | + @Element() |
| 27 | + private int corePoolSize = 20; |
76 | 28 |
|
77 | | - @Deprecated |
78 | | - public void setKeepAliveTime(long keepAliveTime) { |
79 | | - this.keepAliveTime = keepAliveTime; |
80 | | - } |
| 29 | + // 线程池最大值 |
| 30 | + @Element() |
| 31 | + private int maxPoolSize = 200; |
81 | 32 |
|
82 | | - public int getHeart() { |
83 | | - return heart; |
84 | | - } |
| 33 | + // 线程池保持活跃时间(秒) |
| 34 | + @Element() |
| 35 | + private long keepAliveTime = 30L; |
85 | 36 |
|
86 | | - public void setHeart(int heart) { |
87 | | - this.heart = heart; |
88 | | - } |
| 37 | + // 心跳间隔(大于0开启定时监测线程) |
| 38 | + @Element(required = false) |
| 39 | + private int heart; |
89 | 40 |
|
90 | | - public int getCommandSize() { |
91 | | - return commandSize < 10000 ? 10000 : commandSize; |
92 | | - } |
| 41 | + // 缓存命令数 |
| 42 | + @Element(required = false) |
| 43 | + private int commandSize = 100000; |
93 | 44 |
|
94 | | - public void setCommandSize(int commandSize) { |
95 | | - this.commandSize = commandSize; |
96 | | - } |
| 45 | + public ThreadPoolExecutor newThreadPoolExecutor() throws RuntimeException { |
| 46 | + return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, |
| 47 | + new LinkedBlockingQueue<>(commandSize), new IoThreadFactory()); |
| 48 | + } |
97 | 49 |
|
98 | 50 | } |
0 commit comments