Custom thread pool

Update time: 2019-06-21

SOFARPC supports custom business thread pools. A separate business thread pool can be set up for the specified service, isolated from SOFARPC’s global business thread pool. Multiple services can share a single thread pool.

SOFARPC requires that the type of custom thread pool must be


If you publish the service using XML, you can first set the bean of the thread pool whose class is, and then set the bean in the thread-pool-ref attribute of <sofa:global-attrs> tag.

<bean id="helloService" class=""/>

<!-- Customize a thread pool -->
<bean id="customExecutor" class="" init-method="init">
    <property name="corePoolSize" value="10" />
    <property name="maximumPoolSize" value="10" />
    <property name="queueSize" value="0" />

<sofa:service ref="helloService" interface="XXXService">
        <!-- Set the thread pool to a Service -->
        <sofa:global-attrs thread-pool-ref="customExecutor"/>

Use Annotation

If you publish the service using Annotation, you can set the bean of the custom thread pool by setting the userThreadPool attribute of @SofaServiceBinding:

@SofaService(bindings = {@SofaServiceBinding(bindingType = "bolt", userThreadPool = "customThreadPool")})
public class SampleServiceImpl implements SampleService {

Use API in Spring environment

If you publish a service using the API in Spring environment, you can configure a custom thread pool by calling the setUserThreadPool method of BoltBindingParam:

BoltBindingParam boltBindingParam = new BoltBindingParam();
boltBindingParam.setUserThreadPool(new UserThreadPool());

Use API in non-Spring environment

If you publish service using the API in non-Spring environment, you can set a custom thread pool as follows:

UserThreadPool threadPool = new UserThreadPool();

UserThreadPoolManager.registerUserThread(ConfigUniqueNameGenerator.getUniqueName(providerConfig), threadPool);

As above, a custom thread pool is set up for the HelloService service.