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

参考资料

posted @ 2024-03-06 00:04  jackieathome  阅读(50)  评论(0编辑  收藏  举报