<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      java并發:線程池之Executors(ScheduledExecutorService篇)

      Executors

      java.util.concurrent下的Executors工具類提供了如下幾個方法,代碼如下:

          /**
           * Creates a single-threaded executor that can schedule commands
           * to run after a given delay, or to execute periodically.
           * (Note however that if this single
           * thread terminates due to a failure during execution prior to
           * shutdown, a new one will take its place if needed to execute
           * subsequent tasks.)  Tasks are guaranteed to execute
           * sequentially, and no more than one task will be active at any
           * given time. Unlike the otherwise equivalent
           * {@code newScheduledThreadPool(1)} the returned executor is
           * guaranteed not to be reconfigurable to use additional threads.
           *
           * @return the newly created scheduled executor
           */
          public static ScheduledExecutorService newSingleThreadScheduledExecutor() {
              return new DelegatedScheduledExecutorService
                  (new ScheduledThreadPoolExecutor(1));
          }
      
          /**
           * Creates a single-threaded executor that can schedule commands
           * to run after a given delay, or to execute periodically.  (Note
           * however that if this single thread terminates due to a failure
           * during execution prior to shutdown, a new one will take its
           * place if needed to execute subsequent tasks.)  Tasks are
           * guaranteed to execute sequentially, and no more than one task
           * will be active at any given time. Unlike the otherwise
           * equivalent {@code newScheduledThreadPool(1, threadFactory)}
           * the returned executor is guaranteed not to be reconfigurable to
           * use additional threads.
           *
           * @param threadFactory the factory to use when creating new threads
           * @return the newly created scheduled executor
           * @throws NullPointerException if threadFactory is null
           */
          public static ScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory) {
              return new DelegatedScheduledExecutorService
                  (new ScheduledThreadPoolExecutor(1, threadFactory));
          }
      
          /**
           * Creates a thread pool that can schedule commands to run after a
           * given delay, or to execute periodically.
           * @param corePoolSize the number of threads to keep in the pool,
           * even if they are idle
           * @return the newly created scheduled thread pool
           * @throws IllegalArgumentException if {@code corePoolSize < 0}
           */
          public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
              return new ScheduledThreadPoolExecutor(corePoolSize);
          }
      
          /**
           * Creates a thread pool that can schedule commands to run after a
           * given delay, or to execute periodically.
           * @param corePoolSize the number of threads to keep in the pool,
           * even if they are idle
           * @param threadFactory the factory to use when the executor
           * creates a new thread
           * @return the newly created scheduled thread pool
           * @throws IllegalArgumentException if {@code corePoolSize < 0}
           * @throws NullPointerException if threadFactory is null
           */
          public static ScheduledExecutorService newScheduledThreadPool(
                  int corePoolSize, ThreadFactory threadFactory) {
              return new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
          }

      解讀:

      上述代碼片段中的前兩個方法均構造了DelegatedScheduledExecutorService的實例,其定義如下:

          /**
           * A wrapper class that exposes only the ScheduledExecutorService
           * methods of a ScheduledExecutorService implementation.
           */
          private static class DelegatedScheduledExecutorService
                  extends DelegatedExecutorService
                  implements ScheduledExecutorService {
              private final ScheduledExecutorService e;
              DelegatedScheduledExecutorService(ScheduledExecutorService executor) {
                  super(executor);
                  e = executor;
              }
              public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                  return e.schedule(command, delay, unit);
              }
              public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
                  return e.schedule(callable, delay, unit);
              }
              public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
                  return e.scheduleAtFixedRate(command, initialDelay, period, unit);
              }
              public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
                  return e.scheduleWithFixedDelay(command, initialDelay, delay, unit);
              }
          }

      解讀:

      從DelegatedScheduledExecutorService的定義可以看出,其schedule方法依賴于具體的ScheduledExecutorService,即前述代碼片段中構造的ScheduledThreadPoolExecutor實例

      ScheduledExecutorService

      方法列表

       

      類圖

       

      源碼

       

      解讀:

      A、觀察上述兩處代碼片段,可以看到schedule方法內部將 Runable 或者 Callable 包裝成 RunnableScheduledFuture,然后調用 delayedExecute 方法。

      B、scheduleAtFixedRate、scheduleWithFixedDelay 方法內部得實現與之類似。

      C、execute、submit 方法則是調用上述兩個 schedule 方法,見下圖:

       

       

      DelayedWorkQueue

      DelayedWorkQueue 是 ScheduledExecutorService 內部類,具體定義如下:

       

      總覽

      posted @ 2021-08-18 22:56  時空穿越者  閱讀(535)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲性线免费观看视频成熟| 玩弄少妇人妻| 亚洲欧洲国产综合aⅴ无码| 中文字幕久久波多野结衣av| 50岁熟妇的呻吟声对白| 亚洲国产天堂一区二区三区| 亚洲高清偷拍一区二区三区| 91蜜臀国产自产在线观看| 亚洲精品理论电影在线观看| 乌拉特前旗| 日韩大片高清播放器| 国产亚洲精品VA片在线播放| 久久精品国产久精国产一老狼 | 久久精品国产亚洲av熟女| 精品素人AV无码不卡在线观看| 91精品国产午夜福利| 精品无码国产污污污免费| 狠狠五月深爱婷婷网| 久久精品99国产国产精| 狠狠色丁香婷婷综合久久来来去| 377P欧洲日本亚洲大胆| 亚洲欧美综合精品成| 国产在线午夜不卡精品影院| 狠狠v日韩v欧美v| 免费人成视频x8x8国产| 南华县| 亚洲欧美日韩在线不卡| 精品无人区一码二码三码| 国产稚嫩高中生呻吟激情在线视频| AV人摸人人人澡人人超碰| 成人啪啪高潮不断观看| 亚洲精品久久婷婷丁香51| 亚洲www永久成人网站| 亚洲综合在线一区二区三区| 少妇人妻偷人精品免费视频| 人妻影音先锋啪啪av资源 | 欧美性猛交xxxx免费看| 国产午夜福利av在线麻豆| 国产精品成人中文字幕| 综合久久国产九一剧情麻豆| 77se77亚洲欧美在线|