短视频平台源码,聊一聊线程池的预热

短视频平台源码,聊一聊线程池的预热

本文主要研究一下线程池的预热

prestartCoreThread

java/util/concurrent/ThreadPoolExecutor.java

  
复制代码
 /**
     * Starts a core thread, causing it to idly wait for work. This
     * overrides the default policy of starting core threads only when
     * new tasks are executed. This method will return {@code false}
     * if all core threads have already been started.
     *
     * @return {@code true} if a thread was started
     */
    public boolean prestartCoreThread() {
        return workerCountOf(ctl.get()) < corePoolSize &&
            addWorker(null, true);
    }
复制代码

 

ThreadPoolExecutor定义了prestartCoreThread,用于启动一个核心线程

prestartAllCoreThreads

java/util/concurrent/ThreadPoolExecutor.java

复制代码
  /**
     * Starts all core threads, causing them to idly wait for work. This
     * overrides the default policy of starting core threads only when
     * new tasks are executed.
     *
     * @return the number of threads started
     */
    public int prestartAllCoreThreads() {
        int n = 0;
        while (addWorker(null, true))
            ++n;
        return n;
    }
复制代码

 

prestartAllCoreThreads用于启动所有的核心线程

小结

ThreadPoolExecutor提供了prestartCoreThread方法,用于启动一个核心线程,提供了prestartAllCoreThreads方法用于启动所有的核心线程。

以上就是短视频平台源码,聊一聊线程池的预热, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2023-11-09 直播app源码开源,Android 滚动的公告栏
2023-11-09 直播网站源码,CardView如何显示出底背景样式?
2023-11-09 直播app系统源码,python pdf转为图片
2022-11-09 app直播源代码,scroll-view如何自适应页面剩余高度
2022-11-09 直播系统搭建,实现页面多级来回切换支持滑动和点击操作
2022-11-09 直播平台怎么搭建,Android与Js互调之传递图片
2021-11-09 一对一视频源码,登录时输入密码时的显示密码按钮
点击右上角即可分享
微信分享提示