Skip to content

Commit b7f0281

Browse files
authored
add SofaRejectedExecutionHandler for user-customized thread pool (#1450)
* add SofaRejectedExecutionHandler for user custom thread pool * add RejectedExecutionHandler test case * format code * format code
1 parent 512c6fc commit b7f0281

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

core/api/src/main/java/com/alipay/sofa/rpc/server/UserThreadPool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ protected Executor buildExecutor() {
113113
if (prestartAllCoreThreads) {
114114
threadPoolExecutor.prestartAllCoreThreads();
115115
}
116+
threadPoolExecutor.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
116117
return threadPoolExecutor;
117118
}
118119

core/api/src/test/java/com/alipay/sofa/rpc/config/UserThreadPoolManagerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
import com.alipay.sofa.rpc.server.UserThreadPool;
2020
import com.alipay.sofa.rpc.server.UserVirtualThreadPool;
21+
import com.alipay.sofa.rpc.server.SofaRejectedExecutionHandler;
2122
import org.junit.Assert;
2223
import org.junit.Test;
24+
2325
import java.util.Set;
2426
import java.util.concurrent.Executor;
27+
import java.util.concurrent.RejectedExecutionHandler;
2528
import java.util.concurrent.ThreadPoolExecutor;
2629

2730
public class UserThreadPoolManagerTest {
@@ -67,6 +70,16 @@ public void userThreadPoolBuildTest() {
6770
Assert.assertNull(result);
6871
}
6972

73+
@Test
74+
public void testRejectedExecutionHandler() {
75+
UserThreadPool userThreadPool = new UserThreadPool();
76+
Executor executorService = userThreadPool.getUserExecutor();
77+
Assert.assertTrue(executorService instanceof ThreadPoolExecutor);
78+
RejectedExecutionHandler rejectedExecutionHandler = ((ThreadPoolExecutor) executorService)
79+
.getRejectedExecutionHandler();
80+
Assert.assertTrue(rejectedExecutionHandler instanceof SofaRejectedExecutionHandler);
81+
}
82+
7083
@Test
7184
public void userThreadPoolCompatibleTest() {
7285
UserThreadPool userThreadPool = new UserThreadPool();

0 commit comments

Comments
 (0)