1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.thrift;
20
21 import java.util.concurrent.BlockingQueue;
22 import java.util.concurrent.ThreadFactory;
23 import java.util.concurrent.ThreadPoolExecutor;
24 import java.util.concurrent.TimeUnit;
25
26
27
28
29
30
31 public class THBaseThreadPoolExecutor extends ThreadPoolExecutor {
32
33 private ThriftMetrics metrics;
34
35 public THBaseThreadPoolExecutor(int corePoolSize, int maxPoolSize, long keepAliveTime,
36 TimeUnit unit, BlockingQueue<Runnable> workQueue, ThriftMetrics metrics) {
37 this(corePoolSize, maxPoolSize, keepAliveTime, unit, workQueue, null, metrics);
38 }
39
40 public THBaseThreadPoolExecutor(int corePoolSize, int maxPoolSize, long keepAliveTime,
41 TimeUnit unit, BlockingQueue<Runnable> workQueue,
42 ThreadFactory threadFactory,ThriftMetrics metrics) {
43 super(corePoolSize, maxPoolSize, keepAliveTime, unit, workQueue);
44 if (threadFactory != null) {
45 setThreadFactory(threadFactory);
46 }
47 this.metrics = metrics;
48 }
49
50 @Override
51 protected void beforeExecute(Thread t, Runnable r) {
52 super.beforeExecute(t, r);
53 metrics.incActiveWorkerCount();
54 }
55
56 @Override
57 protected void afterExecute(Runnable r, Throwable t) {
58 metrics.decActiveWorkerCount();
59 super.afterExecute(r, t);
60 }
61 }