Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SofaRejectedExecutionHandler for user-customized thread pool #1450

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading