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 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

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要

如何将Tomcat容器替换为Jetty容器

《如何将Tomcat容器替换为Jetty容器》:本文主要介绍如何将Tomcat容器替换为Jetty容器问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Tomcat容器替换为Jetty容器修改Maven依赖配置文件调整(可选)重新构建和运行总结Tomcat容器替

Python使用date模块进行日期处理的终极指南

《Python使用date模块进行日期处理的终极指南》在处理与时间相关的数据时,Python的date模块是开发者最趁手的工具之一,本文将用通俗的语言,结合真实案例,带您掌握date模块的六大核心功能... 目录引言一、date模块的核心功能1.1 日期表示1.2 日期计算1.3 日期比较二、六大常用方法详