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
。
参考资料
本文来自博客园,作者:jackieathome,转载请注明原文链接:https://www.cnblogs.com/jackieathome/p/18055608