1、修改启动时内存参数、并指定JVM时区 (在windows server 2008 下时间少了8个小时):

在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增加系统参数:

window下, 在catalina.bat最前面:

set JAVA_OPTS=-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m

一定加在catalina.bat最前面。

linux下,在catalina.sh最前面增加:

JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Duser.timezone=Asia/Shanghai"

注意:前后二者区别,有无set,有无双引号。

2、线程池配置(Tomcat6下)

使用线程池,用较少的线程处理较多的访问,可提高tomcat处理请求的能力。使用方式:

首先。打开/conf/server.xml,增加

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

maxThreads="500" minSpareThreads="20" maxIdleTime="60000" />

最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60秒。

然后,修改<Connector ...>节点,增加executor属性,如:

<Connector executor="tomcatThreadPool"

port="80" protocol="HTTP/1.1"

connectionTimeout="60000"

keepAliveTimeout="15000"

maxKeepAliveRequests="1"

redirectPort="443"

....../>

注意:可以多个connector公用1个线程池。

3、调整连接相关Connector的参数:

<Connector executor="tomcatThreadPool"

port="80" protocol="HTTP/1.1"

connectionTimeout="60000"

keepAliveTimeout="15000"

maxKeepAliveRequests="1"

redirectPort="443"

maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="100" disableUploadTimeout="true"/>

参数说明:

connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患。通常可设置为30000毫秒。

keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。

maxKeepAliveRequests - 最大长连接个数(1表示禁用,-1表示不限制个数,默认100个。一般设置在100~200之间) the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. Setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 allows an unlimited number of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.

maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。

URIEncoding - 指定Tomcat容器的URL编码格式。

acceptCount - 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理,默认为10个。defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full are refused. The default value is 10.

disableUploadTimeout - 上传时是否使用超时机制

enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false

bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.

maxSpareThreads - 做多空闲连接数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程 the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.

maxThreads - 最多同时处理的连接数,Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。 the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.

minSpareThreads - 最小空闲线程数,Tomcat初始化时创建的线程数 the number of request processing threads that are created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.

minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)

maxProcessors - 最大连接线程数,即:并发处理的最大请求数,默认值为75。(用于Tomcat4中)

备注:

Tomcat4中可通过修改minProcessors和maxProcessors的值来控制线程数。

在Tomcat5+主要对以下参数调整

maxThreads

Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。

acceptCount

指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理。

connnectionTimeout

网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。

minSpareThreads

Tomcat初始化时创建的线程数。

maxSpareThreads

一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。

4、负载均衡、集群的配置

Tomcat6支持分布式部署,可实现集群功能,提高响应能力。

5、利用JMX监控Tomcat运行情况,需手工调整启动参数,如下:

打开cataline.bat,增加一行

set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=10090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"

linux下修改cataline.sh:

JAVA_OPTS="-Dcom.sun.management.jmxremote.port=10090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=%CATALINA_BASE\conf\logging.properties"

注意JDK\jre\lib\management\management.properties文件必须存在。

重新启动tomcat节点,然后用jconsole连接(此处端口wei10090)

6、Tomcat增加一个应用

在server.xml的Host标签中增加行

<Context displayName="OA" docBase="/app/web-apps/GACWP" path="" />

path代表上下文名称,空表示是根路径。

Tomcat_启动参数设置的更多相关文章

  1. tomcat端口修改以及jvm启动参数设置

    1.端口更改:找到config目录下server.xml文件 如下 <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to t ...

  2. Eclipse启动参数设置

    Eclipse启动参数设置 文件路径:安装目录根路径/eclipse.ini 参数注解: [-debug options -vm javaw.exe] 显示JVM当前内存使用量(注:详见下方<让 ...

  3. JVM启动参数设置

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt174 不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断,正 ...

  4. jvm 启动参数设置(转载)

    JVM启动参数 http://onlyor.iteye.com/blog/1722413 博客分类: java java java启动参数共分为三类其一是标准参数(-),所有的JVM实现都必须实现这些 ...

  5. chrome启动参数设置

    chrome禁止本地浏览时加载本地其他文件,可以采用添加启动参数的方式来支持 添加参数为 --allow-file-access-from-files  或者 --disable-web-securi ...

  6. IDEA+SpringBoot项目启动参数设置

    SpringBoot属性加载顺序 顺序 形式 1 在命令行中传入的参数 2 SPRING_APPLICATION_JSON中的属性.SPRING_APPLICATION_JSON是以JSON的格式配置 ...

  7. jvm启动参数设置 -Dfile.encoding=UTF-8 解决freemark乱码

    今天一个spring boot应用windows跑起来后页面显示乱码,加上jvm启动参数为utf-8后,页面显示正常.

  8. Tomcat性能优化(二) 启动参数设置

    一.tomcat绿色版设置方法 进入tomcat/bin目录下,找到catalina.bat文件在文件首行中插入下面这段配置即可. set JAVA_OPTS=-server -Djava.awt.h ...

  9. SpringBoot 启动参数设置环境变量、JVM参数、tomcat远程调试

    java命令的模版:java [-options] -jar jarfile [args...] 先贴一下我的简单的启动命令: java -Xms128m -Xmx256m -Xdebug -Xrun ...

随机推荐

  1. 【20181024T3】小C的宿舍【分治】

    题面 [错解] 好像就是\(|i-j|+|a_i - b_i|\)唉 嗯开始都加i-1,跑一遍,1~(i-1)加1,i~n 减1,线段树维护. 过样例了呢 哎大样例怎么多了那么多啊 跑了个暴力,多得更 ...

  2. C++中的读入输出优化及清新脱俗的宏命令

    C和C++有了#define,从此它就变了模样 宏命令就是#define,#if,#error之类的 本文主要介绍宏命令和相关的骚操作 读入输出优化 inline int read() { int a ...

  3. BZOJ 1707 [Usaco2007 Nov]tanning分配防晒霜(扫描线+贪心+优先队列)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1707 [题目大意] 每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值 防晒霜的作 ...

  4. 【思路】Aizu - 1367 - Rearranging a Sequence

    给你一个1~n排好的数组,每次提一个数到最前面,问你最后形成的序列. 就把他的输入顺序倒过来输出即可.没出现过的再按原序输出. #include<cstdio> using namespa ...

  5. python基础之集合,字符编码

    六.集合类型 1.用途:关系运算 2.定义方式:s = {1,2,’a’} {}内用,分隔开多个元素,每个元素都必须是不可变(即可hash)类型 强调:2.1集合内的元素时无序的 2.2集合内的元素不 ...

  6. JDK源码学习笔记——HashSet LinkedHashSet TreeSet

    你一定听说过HashSet就是通过HashMap实现的 相信我,翻一翻HashSet的源码,秒懂!! 其实很多东西,只是没有静下心来看,只要去看,说不定一下子就明白了…… HashSet 两个属性: ...

  7. 微软笔试Highway问题解析

      High way   时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 In the city, there is a one-way straight highway ...

  8. LRU近期最少使用算法

    LRU(least recently used)最少使用. 假设 序列为 4 3 4 2 3 1 4 2 物理块有3个 则 首轮 4调入内存 4 次轮 3调入内存 3 4 之后 4调入内存 4 3 之 ...

  9. 安装gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabi交叉编译器

    1.开发平台 虚拟机:VMware 12 操作系统:Ubuntu 14.04 64bit 2.准备ARM交叉编译工具包 编译uboot和linux kernel都需要ARM交叉工具链支持,这里使用Li ...

  10. Bestreviewapp给iOS软件写评论赚钱

    BestReviewApp 这是一个评论类的活动,网站上会提供App列表,在iTunes评论这些应用就能获得报酬.目前账号中的余额可通过PayPal或支付宝提取出来.BestReviewApp 开放的 ...