Skip to content

Commit

Permalink
add SofaRejectedExecutionHandler for user-customized thread pool (#1450)
Browse files Browse the repository at this point in the history
* add SofaRejectedExecutionHandler for user custom thread pool

* add RejectedExecutionHandler test case

* format code

* format code
  • Loading branch information
bohrqiu authored Oct 14, 2024
1 parent 512c6fc commit b7f0281
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected Executor buildExecutor() {
if (prestartAllCoreThreads) {
threadPoolExecutor.prestartAllCoreThreads();
}
threadPoolExecutor.setRejectedExecutionHandler(new SofaRejectedExecutionHandler());
return threadPoolExecutor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import com.alipay.sofa.rpc.server.UserThreadPool;
import com.alipay.sofa.rpc.server.UserVirtualThreadPool;
import com.alipay.sofa.rpc.server.SofaRejectedExecutionHandler;
import org.junit.Assert;
import org.junit.Test;

import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

public class UserThreadPoolManagerTest {
Expand Down Expand Up @@ -67,6 +70,16 @@ public void userThreadPoolBuildTest() {
Assert.assertNull(result);
}

@Test
public void testRejectedExecutionHandler() {
UserThreadPool userThreadPool = new UserThreadPool();
Executor executorService = userThreadPool.getUserExecutor();
Assert.assertTrue(executorService instanceof ThreadPoolExecutor);
RejectedExecutionHandler rejectedExecutionHandler = ((ThreadPoolExecutor) executorService)
.getRejectedExecutionHandler();
Assert.assertTrue(rejectedExecutionHandler instanceof SofaRejectedExecutionHandler);
}

@Test
public void userThreadPoolCompatibleTest() {
UserThreadPool userThreadPool = new UserThreadPool();
Expand Down

0 comments on commit b7f0281

Please sign in to comment.