content/references/java-chassis/en_US/build-provider/thread-pool/index.html (390 lines of code) (raw):
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="../../img/favicon.ico" />
<title>Thread pool - ServiceComb Java Chassis Developers Guide</title>
<link rel="stylesheet" href="../../css/theme.css" />
<link rel="stylesheet" href="../../css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css" />
<script>
// Current page data
var mkdocs_page_name = "Thread pool";
var mkdocs_page_input_path = "build-provider/thread-pool.md";
var mkdocs_page_url = null;
</script>
<script src="../../js/jquery-3.6.0.min.js" defer></script>
<!--[if lt IE 9]>
<script src="../../js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../.." class="icon icon-home"> ServiceComb Java Chassis Developers Guide
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../..">Introduction</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../start/terminology/">Glossary</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/architecture/">Architecture</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/development-environment/">Development environment</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../start/first-sample/">Develop the first microservice</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Development Service Provider</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../definition/service-definition/">Service definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../define-contract/">Service contract definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../code-first/">Implicit API definition</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../swagger-annotation/">Use Swagger annotations</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../springmvc/">Develop with SpringMVC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../jaxrs/">Develop with JAX-RS</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../transparent-rpc/">Develop with Transparent RPC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../interface-constraints/">Interface definition and data type</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../listen-address-and-publish-address/">Service listening address and publishing address</a>
</li>
<li class="toctree-l1 current"><a class="reference internal current" href="./">Thread pool</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#concept-description">Concept Description</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#customize-thread-pool">Customize thread pool</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#servicecomb-built-in-thread-pool">ServiceComb built-in thread pool</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="#">Service Configuration</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="../configuration/ratelimite-strategy/">Rate Limiting Policy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../configuration/downgrade-strategy/">Fallback Policy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../configuration/parameter-validator/">Parameter Validator</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../bootup/">Boot-up Process</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../access-log-configuration/">Access Log Configuration</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Writing Service Consumer</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/common-configuration/">Consumer common configuration</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-resttemplate/">Using Rest Template</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/using-AsyncRestTemplate/">Using AsyncRestTemplate</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/develop-consumer-using-rpc/">Using with RPC</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/with-contract/">Contract</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="#">Invoke control</a>
<ul>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/circuit-breaker/">Circuit Breaker</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/flow-control/">Flow Control</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../build-consumer/fault-injection/">Fault Injection</a>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../build-consumer/3rd-party-service-invoke/">Invoke 3rd-party REST services</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Transports</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-servlet/">REST over Servlet</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/rest-over-vertx/">REST over Vertx</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/highway-rpc/">Highway</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../transports/http2/">HTTP2</a>
</li>
</ul>
<p class="caption"><span class="caption-text">General Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/visit-sc/">Access Service Center</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/metrics/">Metrics</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/microservice-invocation-chain/">Microservice invocation chain</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/customized-tracing/">Customized-Tracing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/local-develop-test/">Local development and testing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/http-filter/">Http Filter</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/file-upload/">File Uploading</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/file-download/">File Downloading</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/reactive/">Reactive Programing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/dnsconfig/">DNS Custom Configuration</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/dai-li-she-zhi/">Proxy Settings</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/report-framework-version/">Report framework version</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/cross-app-invocation/">Cross-application invocation</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/secret-field/">Customized serialization and deserialization</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/context/">Using Context to pass control messages</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/produceprocess/">Return value serialization extension</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/CORS/">CORS mechanism</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/AlarmEvent/">Get fuse and instance isolation alarm event information</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/shutdown/">Shutdown gracefully</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/error-handling/">Handling exceptions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/multienvironment/">Multi-environment isolation between microservice instances</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../general-development/thread-model/">Thread Model</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Configuration</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../config/general-config/">General config</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../config/inject-config/">Configuration injection</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Service Capability Open</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../edge/open-service/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/by-servicecomb-sdk/">Using Edge Service</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/nginx/">Using confd and Nginx as edge services</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../edge/zuul/">Use zuul as edge services</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Service Packing and Running</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../packaging/standalone/">Standalone mode</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../packaging/web-container/">WEB container mode</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Micro Service Security</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../security/tls/">Using TLS</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../security/rsa/">Using RSA certification</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Using java chassis in Spring Boot</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/using-java-chassis-in-spring-boot/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/components-for-spring-boot/">spring boot starter for java-chassis</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/java-application/">JAVA application development</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/web-application/">Web development method development</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-between-java-web/">The difference between JAVA application method and Web development method</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../using-java-chassis-in-spring-boot/diff-spring-mvc/">The difference in Spring MVC mode</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Handlers reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/intruduction/">Intruductions</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/loadbalance/">Load Balancing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../references-handlers/publickey/">Public key authentication</a>
</li>
</ul>
<p class="caption"><span class="caption-text">FAQ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/question_answer/">Q & A</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/faq/">FAQ</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../question-and-answer/interface-compatibility/">Micro Service Interface Compatibility FAQ</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../..">ServiceComb Java Chassis Developers Guide</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../.." class="icon icon-home" alt="Docs"></a> »</li>
<li>Development Service Provider »</li>
<li>Thread pool</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="thread-pool">Thread pool</h1>
<h2 id="concept-description">Concept Description</h2>
<p>Thread pool is for executing synchronization business logic.<br />
net send/receive or reactive business logic executing in eventloop, is independent of the thread pool </p>
<p>By default all synchronization methods are executed in a global built-in thread pool<br />
If the business has special requirements, you can specify to use a custom global thread pool, and you can use separate thread pools according to the schemaId or operationId to achieve the effect of the isolated bin. </p>
<h2 id="customize-thread-pool">Customize thread pool</h2>
<ul>
<li>Implementing a thread pool<br />
Choose one of the following methods. </li>
<li>Implement the <code>java.util.concurrent.Executor</code> interface <br />
In order to support elegant exit, if the internal thread is not set to the daemon thread, you also need to implement the <code>java.io.Closeable</code> interface, responsible for destroying the thread pool. </li>
<li>Implement the <code>java.util.concurrent.ExecutorService</code> interface </li>
<li>Declare the thread pool of the implementation as a spring bean </li>
<li>Enable thread pool<br />
Suppose the new thread pool spring bean id is custom-executor </li>
<li>Replace the global thread pool<br />
servicecomb.executors.default: custom-executor</li>
<li>Specify a thread pool dedicated to the schema <br />
servicecomb.executors.Provider.${schemaId}: custom-executor</li>
<li>Specify a thread pool dedicated to the operation <br />
servicecomb.executors.Provider.${schemaId}.${operationId}: custom-executor</li>
</ul>
<h2 id="servicecomb-built-in-thread-pool">ServiceComb built-in thread pool</h2>
<p>In a general thread pool, all threads share a task queue. In this case, all network threads need to apply for the same queue to join the queue. All threads in the thread pool need to grab the task from the same queue. Throughput scenarios, which can lead to competitive conflicts and create performance bottlenecks<br />
Therefore, in order to improve performance, ServiceComb's built-in thread pool is actually a wrapper of real thread pools, allowing multiple sets of thread pools to be configured inside, and each network thread is bound to a set of thread pools to reduce contention conflicts.<br />
<img alt="" src="../../assets/producer-default-executor.png" /></p>
<ul>
<li>Before version 1.2.0 </li>
</ul>
<table>
<thead>
<tr>
<th align="left">Configuration</th>
<th align="left">default</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">servicecomb.executor.default.group</td>
<td align="left">2</td>
<td align="left">Create several sets of thread pools</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.thread-per-group</td>
<td align="left">CPU count</td>
<td align="left">Number of threads per thread pool</td>
</tr>
</tbody>
</table>
<ul>
<li>Version greater than or equal to 1.2.0</li>
</ul>
<table>
<thead>
<tr>
<th align="left">Configuration</th>
<th align="left">default</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">servicecomb.executor.default.group</td>
<td align="left">2</td>
<td align="left">Create several sets of thread pools</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.thread-per-group</td>
<td align="left">100</td>
<td align="left">Maximum number of threads per group of thread pools<br>Deprecated,new name:maxThreads-per-group</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.coreThreads-per-group</td>
<td align="left">25</td>
<td align="left">Minimum number of threads per group of thread pools<br>Threads are not pre-created, but after they have been created, only threads larger than this value will be destroyed by idle.</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.maxThreads-per-group</td>
<td align="left">100</td>
<td align="left">Maximum number of threads per group of thread pools</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.maxIdleSecond-per-group</td>
<td align="left">60</td>
<td align="left">Each thread in the thread pool that exceeds coreThreads-per-group will destroy the thread if the idle timeout</td>
</tr>
<tr>
<td align="left">servicecomb.executor.default.maxQueueSize-per-group</td>
<td align="left">Integer.MAX_VALUE</td>
<td align="left">Maximum length of the task queue in each group of thread pools</td>
</tr>
</tbody>
</table>
</div>
</div><footer>
<div class="rst-footer-buttons" role="navigation" aria-label="Footer Navigation">
<a href="../listen-address-and-publish-address/" class="btn btn-neutral float-left" title="Service listening address and publishing address"><span class="icon icon-circle-arrow-left"></span> Previous</a>
<a href="../configuration/ratelimite-strategy/" class="btn btn-neutral float-right" title="Rate Limiting Policy">Next <span class="icon icon-circle-arrow-right"></span></a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span><a href="../listen-address-and-publish-address/" style="color: #fcfcfc">« Previous</a></span>
<span><a href="../configuration/ratelimite-strategy/" style="color: #fcfcfc">Next »</a></span>
</span>
</div>
<script>var base_url = '../..';</script>
<script src="../../js/theme_extra.js" defer></script>
<script src="../../js/theme.js" defer></script>
<script src="../../search/main.js" defer></script>
<script defer>
window.onload = function () {
SphinxRtdTheme.Navigation.enable(true);
};
</script>
</body>
</html>