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中re模块结合正则表达式的实际应用案例

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

一文深入详解Python的secrets模块

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

Python logging模块使用示例详解

《Pythonlogging模块使用示例详解》Python的logging模块是一个灵活且强大的日志记录工具,广泛应用于应用程序的调试、运行监控和问题排查,下面给大家介绍Pythonlogging模... 目录一、为什么使用 logging 模块?二、核心组件三、日志级别四、基本使用步骤五、快速配置(bas

Python datetime 模块概述及应用场景

《Pythondatetime模块概述及应用场景》Python的datetime模块是标准库中用于处理日期和时间的核心模块,本文给大家介绍Pythondatetime模块概述及应用场景,感兴趣的朋... 目录一、python datetime 模块概述二、datetime 模块核心类解析三、日期时间格式化与

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

Python中的getopt模块用法小结

《Python中的getopt模块用法小结》getopt.getopt()函数是Python中用于解析命令行参数的标准库函数,该函数可以从命令行中提取选项和参数,并对它们进行处理,本文详细介绍了Pyt... 目录getopt模块介绍getopt.getopt函数的介绍getopt模块的常用用法getopt模

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo