【六祎 - Tomcat】Tomcat性能调优 - 参数;性能调优入门
创始人
2024-05-30 16:04:29
0

Tomcat性能调优 - 参数

    • tomcat版本号:8.5.82
      • StandardThreadExecutor 类
      • 配置修改

tomcat版本号:8.5.82

Tomcat的实现在org.apache.catalina.core.StandardThreadExecutor 里面的参数有

点这里→_→ 查看官方文档
在这里插入图片描述

  • maxThreads - Tomcat线程池最多能起的线程数
  • maxConnections - Tomcat最多能并发处理的请求(连接)
  • acceptCount - Tomcat维护最大的对列数
  • minSpareThreads - Tomcat初始化的线程池大小或者说Tomcat初始化线程池最少会有这么多线程。

maxThreads VS maxConnections 的区别

  • maxThreads是指Tomcat线程池最多能起的线程数
  • maxConnections则是Tomcat一瞬间做多能够处理的并发连接数

eg:
      比如maxThreads=1000,maxConnections=800,假设某一瞬间的并发时1000,那么最终Tomcat的线程数将会是800,即同时处理800个请求,剩余200进入队列“排队”,如果acceptCount=100,那么有100个请求会被拒掉。

StandardThreadExecutor 类

public class StandardThreadExecutor extends LifecycleMBeanBaseimplements Executor, ResizableExecutor {protected static final StringManager sm = StringManager.getManager(StandardThreadExecutor.class);// ---------------------------------------------- Properties/*** Default thread priority* 默认线程的优先级*/protected int threadPriority = Thread.NORM_PRIORITY;/*** Run threads in daemon or non-daemon state* 守护线程*/protected boolean daemon = true;/*** Default name prefix for the thread name* 线程名称的前缀*/protected String namePrefix = "tomcat-exec-";/*** max number of threads* 最大线程数默认200个*/protected int maxThreads = 200;/*** min number of threads* 最小空闲线程25个*/protected int minSpareThreads = 25;/*** idle time in milliseconds* 超时时间为6000毫秒*/protected int maxIdleTime = 60000;/*** The executor we use for this component* 线程池容器*/protected ThreadPoolExecutor executor = null;/*** the name of this thread pool* 线程池名称*/protected String name;/*** The maximum number of elements that can queue up before we reject them* 队列最大限度值*/protected int maxQueueSize = Integer.MAX_VALUE;/*** After a context is stopped, threads in the pool are renewed. To avoid* renewing all threads at the same time, this delay is observed between 2* threads being renewed.* 为了避免在上下文停止之后,所有的线程在同一时间段被更新,所以进行线程的延迟操作*/protected long threadRenewalDelay =org.apache.tomcat.util.threads.Constants.DEFAULT_THREAD_RENEWAL_DELAY;//任务队列private TaskQueue taskqueue = null;// ---------------------------------------------- Constructorspublic StandardThreadExecutor() {//empty constructor for the digester}// ---------------------------------------------- Public Methods/*** Start the component and implement the requirements* of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.** @exception LifecycleException if this component detects a fatal error*  that prevents this component from being used*/@Overrideprotected void startInternal() throws LifecycleException {//1.实例化任务队列taskqueue = new TaskQueue(maxQueueSize);//自定义的线程池工厂类,实现了JDK的ThreadFactory接口TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority());//这里的ThreadPoolExecutor是tomcat自定义的(并非是JDK所属的)executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);executor.setThreadRenewalDelay(threadRenewalDelay);//设置任务容器的父级线程池对象taskqueue.setParent(executor);//设置容器启动状态setState(LifecycleState.STARTING);}/*** 停止容器时的生命周期方法,关闭线程池和资源清理* Stop the component and implement the requirements* of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.** @exception LifecycleException if this component detects a fatal error*  that needs to be reported*/@Overrideprotected void stopInternal() throws LifecycleException {setState(LifecycleState.STOPPING);if (executor != null) {executor.shutdownNow();}executor = null;taskqueue = null;}/*** 这个执行线程方法有超时操作,参考 org.apache.catalina.Executor 接口* @param command the runnable task* @param timeout the length of time to wait for the task to complete* @param unit    the units in which timeout is expressed**/@Override@Deprecatedpublic void execute(Runnable command, long timeout, TimeUnit unit) {if (executor != null) {executor.execute(command,timeout,unit);} else {throw new IllegalStateException(sm.getString("standardThreadExecutor.notStarted"));}}/*** JDK默认操作线程的方法,参考java.util.concurrent.Executor 接口* @param command the runnable task*/@Overridepublic void execute(Runnable command) {if (executor != null) {// Note any RejectedExecutionException due to the use of TaskQueue// will be handled by the o.a.t.u.threads.ThreadPoolExecutorexecutor.execute(command);} else {throw new IllegalStateException(sm.getString("standardThreadExecutor.notStarted"));}}... ... .../*** 由于继承了 org.apache.tomcat.util.thread.ResizableExecutor 接口,所以可以重新定义线程池大小* @param corePoolSize 核心线程池大小* @param maximumPoolSize 最大核心线程池大小* @return*/@Overridepublic boolean resizePool(int corePoolSize, int maximumPoolSize) {if (executor == null) {return false;}executor.setCorePoolSize(corePoolSize);executor.setMaximumPoolSize(maximumPoolSize);return true;}
}

配置修改

  
  

  • 引用github
    • tomcat调优

相关内容

热门资讯

新人丨武田中国区总裁单国洪月底... 来源:健识局6月16日晚间,业界流传出武田中国总裁单国洪决定离职的消息。他最后工作时间是6月30日,...
全方位全过程增强超大城市安全韧... 市委中心组学习会今天(6月17日)下午举行,围绕深入贯彻总体国家安全观,建设更高水平平安上海主题,开...
美日贸易谈判告吹 特朗普与石破... 财联社6月17日讯(编辑 夏军雄)日本首相石破茂在七国集团(G7)峰会期间未能与美国总统特朗普达成贸...
泰瑞机器:注塑机可用于塑料玩具... 证券日报网讯泰瑞机器6月17日在互动平台回答投资者提问时表示,公司注塑机可用于塑料玩具部件的生产。
新疆两部法规7月1日起施行 助... 中新网乌鲁木齐6月17日电 (陶拴科 吕怡欣)17日,新疆人大常委会办公厅举行记者会对外公布,《新疆...
新一批农业产业化国家重点龙头企... 转自:四川在线四川在线记者 阚莹莹近日,农业农村部官网公布了新一批农业产业化国家重点龙头企业名单。全...
新瀚新材:控股股东拟询价转让3... 每经AI快讯,6月17日,新瀚新材(301076.SZ)公告称,公司控股股东严留新拟通过询价转让方式...
晶华新材:拟1.5亿元增资子公... 上证报中国证券网讯(记者周方铂)晶华新材公告,为加快推进公司产业整体布局以及实现总体战略目标,提升全...
三特索道:公司旗下千岛湖牧心谷... 证券日报网讯三特索道(维权)6月17日在互动平台回答投资者提问时表示,公司旗下千岛湖牧心谷项目已于2...
LABUBU,为啥这么火! “一BU难求” 中国潮玩何以火爆全球一款来自中国的潮玩LABUBU(拉布布)正在风靡全球。其融合精灵...
兰生股份(600826.SH)... 格隆汇6月17日丨兰生股份(600826.SH)公布,根据2025年证券市场的变化,在投资风险可控且...
二连浩特市税务局精准施策提质效... 转自:新华财经新华财经呼和浩特6月17日电(蔡博腾 杨宇清)在内蒙古自治区,二连浩特市税务局持续优化...
正元智慧两股东减持计划完成,累... 2025年4月26日,正元智慧(维权)集团股份有限公司(以下简称“正元智慧”)在巨潮资讯网披露股东减...
7天4板东信和平:部分项目或产... 人民财讯6月17日电,7天4板东信和平(002017)6月17日晚间披露股票交易异动公告称,公司关注...
持续提升能力作风 服务湖北建成... 十堰广电讯(全媒体记者 赵慧 通讯员 冯倩钰)作为世界领先的商用车制动系统专家,东科克诺尔商用车制动...
破解小区停车难,也可“抄作业”... 转自:上观新闻业主争抢车位矛盾激化、固定车位存在争议、外来车辆“蹭停”顽疾、物业软性管理存在短板……...
上海、山西、海南等地扎实推进深... 据新华社北京6月17日电 在深入贯彻中央八项规定精神学习教育中,上海、山西、海南等地一体推进学查改,...
泰禾智能(603656.SH)... 格隆汇6月17日丨泰禾智能(603656.SH)公布,公司为拓展工商业用户侧储能业务,拟以现金方式收...
京东方A:拟收购彩虹光电30%... 转自:财联社【京东方A:拟收购彩虹光电30%股权】财联社6月17日电,京东方A(000725.SZ)...
东方生物董事长方剑秋提议公司以... 北京商报讯(记者丁宁)6月17日晚间,东方生物(688298)发布公告称,公司于6月17日收到公司董...