Jetty的threadpool模块

2024-03-06 09:04
文章标签 模块 jetty threadpool

本文主要是介绍Jetty的threadpool模块,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Jetty提供的线程池相关的模块,如下:

  • threadpool
  • threadpool-virtual,使用JDK 21提供的virtual threads。
  • threadpool-virtual-preview,使用JDK 19和JDK 20。

注意上述模块不能共存。
启用threadpool模块后再启用threadpool-virtual模块时,将会有类似如下的提示:

ERROR : Module threadpool-virtual provides threadpool, which is already provided by threadpool enabled in [${jetty.base}/start.d/threadpool.ini]Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]java -jar $JETTY_HOME/start.jar --help  # for more information

threadpool

启用threadpool模块,执行如下命令:

java -jar $JETTY_HOME/start.jar --add-modules=threadpool

命令的输出,如下:

INFO  : threadpool      initialized in ${jetty.base}/start.d/threadpool.ini
INFO  : Base directory was modified

threadpool模块的配置文件$JETTY_BASE/start.d/threadpool.ini,内容如下:

# ---------------------------------------
# Module: threadpool
# Enables and configures the Server ThreadPool.
# ---------------------------------------
--modules=threadpool## Thread name prefix.
#jetty.threadPool.namePrefix=qtp<hashCode>## Minimum number of pooled threads.
#jetty.threadPool.minThreads=10## Maximum number of pooled threads.
#jetty.threadPool.maxThreads=200## Number of reserved threads (-1 for heuristic).
#jetty.threadPool.reservedThreads=-1## Whether to use virtual threads, if the runtime supports them.
## Deprecated, use Jetty module 'threadpool-virtual' instead.
#jetty.threadPool.useVirtualThreads=false## Thread idle timeout (in milliseconds).
#jetty.threadPool.idleTimeout=60000## The max number of idle threads that are evicted in one idleTimeout period.
#jetty.threadPool.maxEvictCount=1## Whether to output a detailed dump.
#jetty.threadPool.detailedDump=false

各参数的说明,如下:

  • jetty.threadPool.namePrefix
    线程池中各线程的名称前缀。
  • jetty.threadPool.minThreads
    线程池中线程的最小数量。
  • jetty.threadPool.maxThreads
    线程池中线程的最大数量。
  • jetty.threadPool.reservedThreads
    线程池中保留的线程的数量。
  • jetty.threadPool.useVirtualThreads
    不推荐使用。对于JDK 21,推荐使用threadpool-virtual模块。
  • jetty.threadPool.idleTimeout
    空闲线程从线程池中移除前等待的时长,单位:毫秒,默认值:60000,即60秒。
  • jetty.threadPool.maxEvictCount
    清理空闲线程时,单次操作中被移除掉的线程的数量。
  • jetty.threadPool.detailedDump
    是否导出线程池中各线程的完整的栈。默认值为false,即只输出栈顶。

threadpool-virtual

启用threadpool-virtual模块,执行如下命令:

java -jar $JETTY_HOME/start.jar --add-modules=threadpool-virtual

启用threadpool-virtual模块成功时的输出,如下:

INFO  : threadpool-virtual initialized in ${jetty.base}/start.d/threadpool-virtual.ini
INFO  : Base directory was modified

threadpool-virtual模块的配置文件$JETTY_BASE/start.d/threadpool-virtual.ini,内容如下:

# ---------------------------------------
# Module: threadpool-virtual
# Enables and configures the Server ThreadPool with support for virtual threads in Java 21 or later.
# ---------------------------------------
--modules=threadpool-virtual## Platform threads name prefix.
#jetty.threadPool.namePrefix=qtp<hashCode>## Minimum number of pooled threads.
#jetty.threadPool.minThreads=10## Maximum number of pooled threads.
#jetty.threadPool.maxThreads=200## Number of reserved threads (-1 for heuristic).
#jetty.threadPool.reservedThreads=-1## Thread idle timeout (in milliseconds).
#jetty.threadPool.idleTimeout=60000## The max number of idle threads that can be evicted in one idleTimeout period.
#jetty.threadPool.maxEvictCount=1## Whether to output a detailed dump.
#jetty.threadPool.detailedDump=false## Virtual threads name prefix.
#jetty.threadPool.virtual.namePrefix=qtp<hashCode>-virtual-## Whether virtual threads inherits the values of inheritable thread locals.
#jetty.threadPool.virtual.inheritInheritableThreadLocals=true

各参数的说明,如下:

  • jetty.threadPool.namePrefix
    threadPool
  • jetty.threadPool.minThreads
    threadPool
  • jetty.threadPool.maxThreads
    threadPool
  • jetty.threadPool.reservedThreads
    threadPool
  • jetty.threadPool.idleTimeout
    threadPool
  • jetty.threadPool.maxEvictCount
    threadPool
  • jetty.threadPool.detailedDump
    threadPool
  • jetty.threadPool.virtual.namePrefix
    virtual threads的线程名称的前缀。
  • jetty.threadPool.virtual.inheritInheritableThreadLocals
    是否复用ThreadLocal对象。默认值为true

threadpool-virtual-preview

启用threadpool-virtual-preview模块,执行如下命令:

java -jar $JETTY_HOME/start.jar --add-modules=threadpool-virtual-preview

启用threadpool-virtual-preview模块成功时的输出,如下:

INFO  : threadpool-virtual-preview initialized in ${jetty.base}/start.d/threadpool-virtual-preview.ini
INFO  : Base directory was modified

threadpool-virtual-preview模块的配置文件$JETTY_BASE/start.d/threadpool-virtual-preview.ini,内容如下:

# ---------------------------------------
# Module: threadpool-virtual-preview
# Enables and configures the Server ThreadPool with support for virtual threads in Java 19 and Java 20.
# ---------------------------------------
--modules=threadpool-virtual-preview## Platform threads name prefix.
#jetty.threadPool.namePrefix=qtp<hashCode>## Minimum number of pooled threads.
#jetty.threadPool.minThreads=10## Maximum number of pooled threads.
#jetty.threadPool.maxThreads=200## Number of reserved threads (-1 for heuristic).
#jetty.threadPool.reservedThreads=-1## Thread idle timeout (in milliseconds).
#jetty.threadPool.idleTimeout=60000## The max number of idle threads that can be evicted in one idleTimeout period.
#jetty.threadPool.maxEvictCount=1## Whether to output a detailed dump.
#jetty.threadPool.detailedDump=false## Virtual threads name prefix.
#jetty.threadPool.virtual.namePrefix=qtp<hashCode>-virtual-## Whether virtual threads are allowed to set thread locals.
#jetty.threadPool.virtual.allowSetThreadLocals=true## Whether virtual threads inherits the values of inheritable thread locals.
#jetty.threadPool.virtual.inheritInheritableThreadLocals=true

各参数的说明,如下:

  • jetty.threadPool.namePrefix
    threadPool
  • jetty.threadPool.minThreads
    threadPool
  • jetty.threadPool.maxThreads
    threadPool
  • jetty.threadPool.reservedThreads
    threadPool
  • jetty.threadPool.idleTimeout
    threadPool
  • jetty.threadPool.maxEvictCount
    threadPool
  • jetty.threadPool.detailedDump
    threadPool
  • jetty.threadPool.virtual.namePrefix
    virtual threads的线程名称的前缀。
  • jetty.threadPool.virtual.allowSetThreadLocals
    是否允许virtual threads记录ThreadLocal类型的对象。默认值为true
  • jetty.threadPool.virtual.inheritInheritableThreadLocals
    是否复用ThreadLocal对象。默认值为true

参考资料

  • 虚拟线程原理及性能分析
  • 聊一聊JDK21-虚拟线程
  • Java高并发革命!JDK19新特性——虚拟线程(Virtual Threads)
  • Virtual Threads 虚拟线程

这篇关于Jetty的threadpool模块的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/779523

相关文章

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服

Python利用自带模块实现屏幕像素高效操作

《Python利用自带模块实现屏幕像素高效操作》这篇文章主要为大家详细介绍了Python如何利用自带模块实现屏幕像素高效操作,文中的示例代码讲解详,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、获取屏幕放缩比例2、获取屏幕指定坐标处像素颜色3、一个简单的使用案例4、总结1、获取屏幕放缩比例from

nginx-rtmp-module模块实现视频点播的示例代码

《nginx-rtmp-module模块实现视频点播的示例代码》本文主要介绍了nginx-rtmp-module模块实现视频点播,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习... 目录预置条件Nginx点播基本配置点播远程文件指定多个播放位置参考预置条件配置点播服务器 192.

多模块的springboot项目发布指定模块的脚本方式

《多模块的springboot项目发布指定模块的脚本方式》该文章主要介绍了如何在多模块的SpringBoot项目中发布指定模块的脚本,作者原先的脚本会清理并编译所有模块,导致发布时间过长,通过简化脚本... 目录多模块的springboot项目发布指定模块的脚本1、不计成本地全部发布2、指定模块发布总结多模

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

Node.js 中 http 模块的深度剖析与实战应用小结

《Node.js中http模块的深度剖析与实战应用小结》本文详细介绍了Node.js中的http模块,从创建HTTP服务器、处理请求与响应,到获取请求参数,每个环节都通过代码示例进行解析,旨在帮... 目录Node.js 中 http 模块的深度剖析与实战应用一、引言二、创建 HTTP 服务器:基石搭建(一

python中的与时间相关的模块应用场景分析

《python中的与时间相关的模块应用场景分析》本文介绍了Python中与时间相关的几个重要模块:`time`、`datetime`、`calendar`、`timeit`、`pytz`和`dateu... 目录1. time 模块2. datetime 模块3. calendar 模块4. timeit

Python模块导入的几种方法实现

《Python模块导入的几种方法实现》本文主要介绍了Python模块导入的几种方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录一、什么是模块?二、模块导入的基本方法1. 使用import整个模块2.使用from ... i

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

深入探索协同过滤:从原理到推荐模块案例

文章目录 前言一、协同过滤1. 基于用户的协同过滤(UserCF)2. 基于物品的协同过滤(ItemCF)3. 相似度计算方法 二、相似度计算方法1. 欧氏距离2. 皮尔逊相关系数3. 杰卡德相似系数4. 余弦相似度 三、推荐模块案例1.基于文章的协同过滤推荐功能2.基于用户的协同过滤推荐功能 前言     在信息过载的时代,推荐系统成为连接用户与内容的桥梁。本文聚焦于