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

参考资料

Jetty的threadpool模块的更多相关文章

  1. python3 线程池-threadpool模块与concurrent.futures模块

    多种方法实现 python 线程池 一. 既然多线程可以缩短程序运行时间,那么,是不是线程数量越多越好呢? 显然,并不是,每一个线程的从生成到消亡也是需要时间和资源的,太多的线程会占用过多的系统资源( ...

  2. Python之路(第四十六篇)多种方法实现python线程池(threadpool模块\multiprocessing.dummy模块\concurrent.futures模块)

    一.线程池 很久(python2.6)之前python没有官方的线程池模块,只有第三方的threadpool模块, 之后再python2.6加入了multiprocessing.dummy 作为可以使 ...

  3. Jetty使用教程(四:21-22)—Jetty开发指南

    二十一.嵌入式开发 21.1 Jetty嵌入式开发HelloWorld 本章节将提供一些教程,通过Jetty API快速开发嵌入式代码 21.1.1 下载Jetty的jar包 Jetty目前已经把所有 ...

  4. Jetty源码分析(一)

    一.目的 1.了解jetty组成架构: 2.学习jetty启动过程: 3.学习请求访问过程: 4.学习jetty内各模块作用,学习各模块内部代码: 二.jetty版本 本文所学习的jetty版本为:9 ...

  5. Windows 上的 Jetty 小工具

    做项目经常遇到需要开发Java应用,我喜欢用Jetty进行开发.部署,主要是由于Jetty的轻量级. Jetty 项目主页:http://www.eclipse.org/jetty/, 最新版9.30 ...

  6. Jetty应用服务器的安装详解

    Jetty是一个开源的Servlet容器和应用服务器,它极度轻量级.高便携性.功能强大.灵活和扩展性好,而且支持各种技术如SPDY.WebSocket.OSGi.JMX.JNDI和JAAS.Jetty ...

  7. Jetty开发指导:HTTP Client

    介绍 Jetty HTTP client模块提供易用的API.工具类和一个高性能.异步的实现来运行HTTP和HTTPS请求. Jetty HTTP client模块要求Java版本号1.7或者更高,J ...

  8. 45、concurrent.futures模块与协程

    concurrent.futures  —Launching parallel tasks    concurrent.futures模块同时提供了进程池和线程池,它是将来的使用趋势,同样我们之前学习 ...

  9. 35、concurrent.futures模块与协程

    concurrent.futures  —Launching parallel tasks    concurrent.futures模块同时提供了进程池和线程池,它是将来的使用趋势,同样我们之前学习 ...

  10. python线程池(threadpool)

    一.安装 pip install threadpool 二.使用介绍 (1)引入threadpool模块 (2)定义线程函数 (3)创建线程 池threadpool.ThreadPool() (4)创 ...

随机推荐

  1. 麒麟系统开发笔记(四):从Qt源码编译安装之编译安装QtCreator4.8.1,并配置编译测试Demo

    前言   本篇紧接上一篇,上一篇已经从Qt源码编译了Qt,那么Qt开发的IDE为QtCreator,本篇从源码编译安装QtCreator,并配置好构建套件,运行Demo并测试.   QtCreator ...

  2. c# rdkafka 设置偏移量(offset)

    参考资料: librdkafka: 如何设置Kafka消费者订阅消息的起始偏移位置 领导要求kafka消费者端消费最新的数据. 不知道怎么设置偏移量,查了资料. 用惯了封装好的东西,都不知道怎么设置了 ...

  3. Spring + JAX-WS : ‘xxx’ is an interface, and JAXB can’t handle interfaces 错误解决方法

    错误栈 Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotatio ...

  4. 【Azure 批处理 】Azure Batch门户中创建自定义作业模式失败解决办法

    问题描述 跟随官方文档,快速创建Azure批处理任务(快速入门:在 Azure 门户中运行第一个 Batch 作业),在添加作业时,选择"自定义模式",并添加文档中所提供的简单命令 ...

  5. Netty笔记(7) - 使用Netty 模仿 Dubbo 实现简单的 远程调用

    使用Netty 模仿 Dubbo 实现简单的 远程调用 使用 java的反射 动态代理 加 Netty的远程访问 实现根据接口的RPC 远程调用 定义两个公共接口: public interface ...

  6. Dungeon Master 题解

    这道题的题意简单来说:就是在3D迷宫里找出口,也就是三维地图,需要用到三维数组 由于本人写代码极易出错,所以在输入三维数组的时候修改了c(column,即列)的值,重复定义了没看到==,后面改成定义成 ...

  7. 虚拟机和开发板之间通过NFS互联

    简介 NFS是Network File System的首字母缩写.它是一种分布式协议,使客户端可以访问远程服务器上的共享文件.它允许网络中的计算机之间通过TCP/IP网络共享资源. 配置过程 安装NF ...

  8. 云计算 - 内容分发网络CDN技术与应用全解

    在这篇全面解析CDN的技术文章中,我们深入探讨了CDN的基础概念.核心架构.多样化产品和在不同行业中的应用案例.文章揭示了CDN技术如何优化内容分发,提升用户体验,并展望了CDN面临的挑战和未来发展趋 ...

  9. 感慨 vscode 支持win7最后一个版本 1.70.3 于2022年7月发布

    为什么 家里电脑一直是win7,也懒的升级,nodejs也不能用最新的,没想到vscode也停产了 https://code.visualstudio.com/updates/v1_70 后记 别用u ...

  10. 记一次maven不下来的经历

    起因:自己手动搭建个项目,参考公司项目使用了很多依赖,但是当自己maven时候发现一个依赖怎么也down不下来,就此展开了一番折腾 这个依赖叫 <dependency> <group ...