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

相关文章

Python中logging模块用法示例总结

《Python中logging模块用法示例总结》在Python中logging模块是一个强大的日志记录工具,它允许用户将程序运行期间产生的日志信息输出到控制台或者写入到文件中,:本文主要介绍Pyt... 目录前言一. 基本使用1. 五种日志等级2.  设置报告等级3. 自定义格式4. C语言风格的格式化方法

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

Nginx添加内置模块过程

《Nginx添加内置模块过程》文章指导如何检查并添加Nginx的with-http_gzip_static模块:确认该模块未默认安装后,需下载同版本源码重新编译,备份替换原有二进制文件,最后重启服务验... 目录1、查看Nginx已编辑的模块2、Nginx官网查看内置模块3、停止Nginx服务4、Nginx

python urllib模块使用操作方法

《pythonurllib模块使用操作方法》Python提供了多个库用于处理URL,常用的有urllib、requests和urlparse(Python3中为urllib.parse),下面是这些... 目录URL 处理库urllib 模块requests 库urlparse 和 urljoin编码和解码

创建springBoot模块没有目录结构的解决方案

《创建springBoot模块没有目录结构的解决方案》2023版IntelliJIDEA创建模块时可能出现目录结构识别错误,导致文件显示异常,解决方法为选择模块后点击确认,重新校准项目结构设置,确保源... 目录创建spChina编程ringBoot模块没有目录结构解决方案总结创建springBoot模块没有目录

idea Maven Springboot多模块项目打包时90%的问题及解决方案

《ideaMavenSpringboot多模块项目打包时90%的问题及解决方案》:本文主要介绍ideaMavenSpringboot多模块项目打包时90%的问题及解决方案,具有很好的参考价值,... 目录1. 前言2. 问题3. 解决办法4. jar 包冲突总结1. 前言之所以写这篇文章是因为在使用Mav

Python标准库datetime模块日期和时间数据类型解读

《Python标准库datetime模块日期和时间数据类型解读》文章介绍Python中datetime模块的date、time、datetime类,用于处理日期、时间及日期时间结合体,通过属性获取时间... 目录Datetime常用类日期date类型使用时间 time 类型使用日期和时间的结合体–日期时间(

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数

Python中re模块结合正则表达式的实际应用案例

《Python中re模块结合正则表达式的实际应用案例》Python中的re模块是用于处理正则表达式的强大工具,正则表达式是一种用来匹配字符串的模式,它可以在文本中搜索和匹配特定的字符串模式,这篇文章主... 目录前言re模块常用函数一、查看文本中是否包含 A 或 B 字符串二、替换多个关键词为统一格式三、提

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基