<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                Spring 提供了接口 TaskExecutor,并提供了該接口的一些實現類,如果要自定義線程池,覆蓋 Spring 默認的實現類即可。Spring 提供的實現類如下: ```java SimpleAsyncTaskExecutor Spring 默認線程池:該實現不會重用任何線程,每次調用都會創建一個新的線程。 SyncTaskExecutor 該實現不會異步的執行。相反,每次調用都在發起調用的線程中執行。 它的主要用處是在不需要多線程的時候,比如簡單的測試用例。 ConcurrentTaskExecutor 該實現是對 Java 5 java.util.concurrent.Executor 類的包裝。 有另一個 ThreadPoolTaskExecutor 類更為好用,它暴露了 Executor 的配置參數作為 bean 屬性。 ThreadPoolTaskExecutor 該實現最常用、最通用的一種實現。它包含了 java.util.concurrent.ThreadPoolExecutor 的屬性, 并且用 TaskExecutor 進行包裝。 ``` <br/> 自定義線程池步驟如下: **1. 自定義線程池** ```java @Configuration public class AsyncConfig { @Bean("asyncExecutor") public Executor asyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); //線程核心數 executor.setCorePoolSize(5); //最大線程數 executor.setMaxPoolSize(5); //隊列容量大小 executor.setQueueCapacity(Integer.MAX_VALUE); //線程拒絕策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //初始化線程池 executor.initialize(); return executor; } } ``` **2. 注解`@Async`引用自定義的線程池** ```java @Slf4j @Service public class AsyncService { @Async public void async01() { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("AsyncService -> async01"); } @Async("asyncExecutor") public void async05() { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("AsyncService -> async05"); } } ``` 如上自定義線程池是全局的,所以以`@Async`,還是以`@Async("asyncExecutor")`所使用的線程池都是自定義的。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看