|
22 | 22 | import java.util.concurrent.TimeUnit; |
23 | 23 | import java.util.concurrent.atomic.AtomicInteger; |
24 | 24 |
|
25 | | -public class AmazonSnsThreadPoolExecutor extends ThreadPoolExecutor { |
| 25 | +import com.amazon.sns.messaging.lib.concurrent.ThreadFactoryProvider; |
26 | 26 |
|
| 27 | +public class AmazonSnsThreadPoolExecutor extends ThreadPoolExecutor { |
| 28 | + |
27 | 29 | private final AtomicInteger activeTaskCount = new AtomicInteger(); |
28 | | - |
| 30 | + |
29 | 31 | private final AtomicInteger failedTaskCount = new AtomicInteger(); |
30 | | - |
| 32 | + |
31 | 33 | private final AtomicInteger succeededTaskCount = new AtomicInteger(); |
32 | | - |
| 34 | + |
33 | 35 | public AmazonSnsThreadPoolExecutor(final int maximumPoolSize) { |
34 | | - super(0, maximumPoolSize, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), new BlockingSubmissionPolicy(30000)); |
| 36 | + super(0, maximumPoolSize, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), ThreadFactoryProvider.getThreadFactory(), new BlockingSubmissionPolicy(30000)); |
35 | 37 | } |
36 | | - |
| 38 | + |
37 | 39 | public int getActiveTaskCount() { |
38 | | - return activeTaskCount.get(); |
| 40 | + return this.activeTaskCount.get(); |
39 | 41 | } |
40 | | - |
| 42 | + |
41 | 43 | public int getFailedTaskCount() { |
42 | | - return failedTaskCount.get(); |
| 44 | + return this.failedTaskCount.get(); |
43 | 45 | } |
44 | | - |
| 46 | + |
45 | 47 | public int getSucceededTaskCount() { |
46 | | - return succeededTaskCount.get(); |
| 48 | + return this.succeededTaskCount.get(); |
47 | 49 | } |
48 | | - |
| 50 | + |
| 51 | + public int getQueueSize() { |
| 52 | + return getQueue().size(); |
| 53 | + } |
| 54 | + |
49 | 55 | @Override |
50 | 56 | protected void beforeExecute(final Thread thread, final Runnable runnable) { |
51 | 57 | try { |
52 | 58 | super.beforeExecute(thread, runnable); |
53 | 59 | } finally { |
54 | | - activeTaskCount.incrementAndGet(); |
| 60 | + this.activeTaskCount.incrementAndGet(); |
55 | 61 | } |
56 | 62 | } |
57 | | - |
| 63 | + |
58 | 64 | @Override |
59 | 65 | protected void afterExecute(final Runnable runnable, final Throwable throwable) { |
60 | 66 | try { |
61 | 67 | super.afterExecute(runnable, throwable); |
62 | 68 | } finally { |
63 | 69 | if (Objects.nonNull(throwable)) { |
64 | | - failedTaskCount.incrementAndGet(); |
| 70 | + this.failedTaskCount.incrementAndGet(); |
65 | 71 | } else { |
66 | | - succeededTaskCount.incrementAndGet(); |
| 72 | + this.succeededTaskCount.incrementAndGet(); |
67 | 73 | } |
68 | | - activeTaskCount.decrementAndGet(); |
| 74 | + this.activeTaskCount.decrementAndGet(); |
69 | 75 | } |
70 | 76 | } |
71 | 77 |
|
|
0 commit comments