Deployment and optimization of Tomcat (thief details)

Table of contents

 1. Introduction to Tomcat server

1. Tomcat server

2. Three core components of Tomcat

3、 Java Servlet

4. The full name of JSP is Java Server Pages

5. Tomcat functional component structure

6. Container structure analysis

 7. Tomcat request process

Two: Tomcat deployment and installation

1. Turn off the firewall and upload the required software package

 2. Install JDK

3. Set JDK environment variables 

4. Write a java script to verify

5. Install and start Tomcat

 6. Join the system environment

7. Optimize tomcat startup speed

Three: Tomcat virtual host configuration

1. Create qhw and benet project directories and files

 2. Modify the Tomcat main configuration file server.xml

3. Client browser access verification

Four: Tomcat multi-instance deployment

1. Install jdk

2. Install tomcat

3. Configure tomcat environment variables

4. Modify the server.xml file in tomcat2, requiring each tomcat instance to be configured without duplicate port numbers

 5. Modify the startup.sh and shutdown.sh files in each tomcat instance, and add tomcat environment variables

 6. Start /bin/startup.sh in each tomcat 

 7. Browser access test

Five: Tomcat optimization

1. Tomcat configuration file parameter optimization

 2. What is the default port of Tomcat and how to modify it

 3. Memory optimization (JVM optimization)


 1. Introduction to Tomcat server

1. Tomcat server

    Tomcat server is a free and open source web application server. It is a lightweight application server. It is widely used in small and medium-sized systems and occasions where there are not many concurrent access users. It is the first choice for developing and debugging JSP programs.
Generally speaking, although Tomcat has the same function as web servers such as Apache or Nginx, it has the function of processing HTML pages. However, because its ability to process static HTML is far less than that of Apache or Nginx, Tomcat is usually used as a Servlet and JSP container. rear end.

Summary:

1) Free, open source web application server
2) A core project of the Apache Software Foundation (Apache Software Foundation) Jakarta project
3) Jointly developed by Apache, Sun and some companies and individuals
4) Deeply popular with Java Loved by enthusiasts and recognized by some software developers
5) Currently popular Web application server

2. Three core components of Tomcat

Tomcat consists of a series of components, of which there are three core components

  • Web container: Complete the function of the Web server.
  • Servlet container: the name is catalina, used to process Servlet code.
  • JSP container: used to translate JSP dynamic web pages into Servlet codes.

3、 Java Servlet

Servlet is the abbreviation of Java Servlet. It can be understood as a service connector, a server-side program written in Java, and has the characteristics of being independent of platforms and protocols. Simple understanding: servlet is a middleware, including interfaces and methods. Connect the client to the database to realize the creation of dynamic web pages.

A program running on a web server or application server that acts as an intermediary between a request from a web browser or other HTTP client and a database or application on the HTTP server. Using servlets, you can collect user input from web page forms, render records from databases or other sources, and create web pages dynamically. Similar to CGI (Common Gateway Interface) functionality.

4. The full name of JSP is Java Server Pages

The full name of JSP is Java Server Pages, which is a dynamic web page development technology. It uses JSP tags to insert Java code in HTML web pages. Tags usually start with <% and end with %>.
JSP is a Java servlet primarily used to implement the user interface portion of a Java web application.
JSP takes user input data through web page forms, accesses databases and other data sources, and then dynamically creates web pages.

5. Tomcat functional component structure

There are two core functions of Tomcat, the Connector responsible for receiving and feeding back external requests, and the Container responsible for processing requests. Among them, the connector and the container complement each other and together constitute the basic web service Service. Each Tomcat server can manage multiple Services.

Connector : Responsible for receiving and responding to external requests. It is the communication hub between Tomcat and the outside world. The listening port receives external requests, processes the requests and passes them to the container for business processing, and finally responds to the outside world with the processed results of the container.
Container : responsible for processing business logic internally. Its interior consists of four containers, Engine, Host, Context and Wrapper, which are used to manage and invoke Servlet-related logic.
Service : Web service provided externally. It mainly includes two core components, Connector and Container, and other functional components. Tomcat can manage multiple services, and each service is independent of each other.

6. Container structure analysis

Each Service will contain a Container container. There are 4 sub-containers inside the Container:
The functions of the 4 sub-containers are:
(1) Engine : Engine, used to manage multiple virtual hosts, a Service can only have one Engine at most;
(2) Host : Represents a virtual host , can also be called a site, and the site can be added by configuring the Host;
(3) Context : represents a Web application, including multiple Servlet wrappers;
(4) Wrapper : wrapper, the bottom layer of the container. Each Wrapper encapsulates a Servlet, which is responsible for the creation, execution and destruction of object instances.

Engine, Host, Context and Wrapper, these four containers belong to parent-child relationship.
A container can manage multiple virtual hosts by one engine. Each virtual host can manage multiple web applications. Each web application will have multiple servlet wrappers.

 7. Tomcat request process

(1) The user enters the URL in the browser, and the request is sent to port 8080 of the local machine, and is obtained by the Connector listening there; (2) The Connector hands
the request to the Engine (Container) of the Service where it is located for processing, and Wait for the response from Engine;
(3) The request is invoked layer by layer among the four containers of Engine, Host, Context and Wrapper, and finally executes the corresponding business logic and data storage in the Servlet.
(4) After execution, the request response is returned layer by layer among the Context, Host, and Engine containers, and finally returned to the Connector, and returned to the client through the Connector.

Two: Tomcat deployment and installation

1) Download and install the JDK

2) Install and start Tomcat

3) Configure the virtual host

Note: jdk must be installed before deploying Tomcat, because jdk is a necessary environment for Tomcat to run.

1. Turn off the firewall and upload the required software package

Turn off the firewall, and transfer the software packages required to install Tomcat to the /opt directory

所需安装包为:
apache-tomcat-9.0.16.tar.gz  
jdk-8u201-linux-x64.rpm 

systemctl stop firewalld.service 
systemctl disable firewalld.service 
setenforce 0

 
2. Install JDK

rpm -qpl jdk-8u201-linux-x64.rpm
rpm -ivh jdk-8u201-linux-x64.rpm 
java -version

3. Set JDK environment variables 

vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

source /etc/profile.d/java.sh
java -version

 

 

Related explanation:

JDK : java development kit (java development tool)
JRE : java runtime environment (java runtime environment)
JVM : java virtuak machine (java virtual machine), so that java programs can run class files on multiple platforms.
CLASSPATH : Tell jvm where to put the class to use or execute, so that the JVM can load the class file.
tools.jar : It is used when the system is used to compile a class, that is, it is used when javac is executed.
dt.jar : dt.jar is a class library about the operating environment, mainly the swing package. 

4. Write a java script to verify

cd /opt
vim abc.java
#类名、接口名命令:英文大小写字母、数字字符、$和_,不能使用关键字和数字开头;
一个单词命名时第一个单词的首字母要大写;多单词组成时,所有单词的首字母大写:XxxYyyZzz(大驼峰命名法)
public class abc {
  public static void main(String[] args){
    System.out.println("Hello World!")
  }
}

[root@localhost?opt]#javac abc.java      #用来检测JDK环境是否设置成功
[root@localhost?opt]#java abc
Hello World!

 5. Install and start Tomcat

cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mv apache-tomcat-9.0.16 /usr/local/tomcat
##启动tomcat ##
#后台启动
/usr/local/tomcat/bin/startup.sh 
或
/usr/local/tomcat/bin/catalina.sh start	
	
#前台启动
/usr/local/tomcat/bin/catalina.sh run		

netstat -natp | grep 8080

 Virtual machine browser access http://192.168.231.102:8080

 6. Join the system environment

1. #先关闭服务
/usr/local/tomcat/bin/shutdown.sh
 
2. #添加用户设置属主属组
useradd -s /sbin/nologin tomcat
chown tomcat:tomcat /usr/local/tomcat -R

3. #新建服务文件
vim /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target
 
[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat
 
[Install]
WantedBy=multi-user.target
 
4. #重新加载服务,并开启,查看是否成功启动
systemctl daemon-reload
systemctl start tomcat
ss -ntap |grep 8080

7. Optimize tomcat startup speed

The first time you start tomcat, you may find that Tomcat starts very slowly. By default, it may take tens of seconds. You can modify the jdk parameters to change it.

vim /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security
--117行--修改
securerandom.source=file:/dev/urandom

/usr/local/tomcat/bin/shutdown.sh 
/usr/local/tomcat/bin/startup.sh 

ll /usr/local/tomcat/

 Main directory description:

  • bin : store the script files for starting and shutting down Tomcat, such as catalina.sh, startup.sh, shutdown.sh 
  • conf : stores various configuration files of the Tomcat server, such as the main configuration file server.xml and the application default deployment description file web.xml 
  • lib : The jar package that stores the library files needed for Tomcat to run, generally without any changes
  • logs : store the logs when Tomcat is executed
  • temp : stores the files generated when Tomcat is running
  • webapps : The directory that stores Tomcat's default web application project resources
  • work : Tomcat's working directory, which stores web application code generation and compilation files

Three: Tomcat virtual host configuration

In many cases, the company will have multiple projects that need to be run. Generally, multiple Tomcat services will not be run on one server, which will consume too many system resources. At this point, you need to use the Tomcat virtual host.
For example, now add two domain names www.qhw.com and www.benet.com, hoping to access different project contents through these two domain names.

1. Create qhw and benet project directories and files

mkdir /usr/local/tomcat/webapps/qhw
mkdir /usr/local/tomcat/webapps/benet
echo "This is qhw page\!" > /usr/local/tomcat/webapps/qhw/index.jsp
echo "This is benet page\!" > /usr/local/tomcat/webapps/benet/index.jsp

 2. Modify the Tomcat main configuration file server.xml

vim /usr/local/tomcat/conf/server.xml
--165行前--插入
<Host name="www.qhw.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
	<Context docBase="/usr/local/tomcat/webapps/qhw" path="" reloadable="true" />
</Host>

<Host name="www.benet.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
	<Context docBase="/usr/local/tomcat/webapps/benet" path="" reloadable="true" />
</Host>



/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh

 Related notes:

Host name : host name
appBase : Tomcat program working directory, relative path is webapps, absolute path is /usr/local/tomcat/webapps
unpackWARs : whether to
decompress war packageDeploy
xmlValidation : Whether to verify the flag of the validity check of the xml file
xmlNamespaceAware : Whether to enable the xml namespace, set this value and xmlValidation to true, indicating that the validity check is performed on the web.xml file

docBase : the directory
path of the WEB application: set the access URI to the root directory of the WEB application
reloadable : whether to reload when the program is changed

3. Client browser access verification

echo "192.168.231.102 www.qhw.com www.benet.com" >> /etc/hosts

 When the browser visits http://.qhw.com:8080/, the page displays This is kgc page\! When 
the browser visits http://www.benet.com:8080/, the page displays This is benet page\!

HTTP request process:
(1) The port the Connector monitors is 8080. Since the requested port matches the listening port, the connector accepts the request.
(2) Because the default virtual host of the engine is www.kgc.com, and the directory of the virtual host is webapps. So the request finds the tomcat/webapps directory.
(3) The access path is the root path, and the URI is empty, that is, the empty is the application name of the Web program, that is, the context. At this time, the request finds the /usr/local/tomcat/webapps/kgc directory, parses index.jsp and returns it.

Four: Tomcat multi-instance deployment

1. Install jdk

2. Install tomcat

cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mkdir /usr/local/tomcat
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2

3. Configure tomcat environment variables

vim /etc/profile.d/tomcat.sh
#tomcat1
export CATALINA_HOME1=/usr/local/tomcat/tomcat1
export CATALINA_BASE1=/usr/local/tomcat/tomcat1
export TOMCAT_HOME1=/usr/local/tomcat/tomcat1

#tomcat2
export CATALINA_HOME2=/usr/local/tomcat/tomcat2
export CATALINA_BASE2=/usr/local/tomcat/tomcat2
export TOMCAT_HOME2=/usr/local/tomcat/tomcat2


source /etc/profile.d/tomcat.sh

4. Modify the server.xml file in tomcat2, requiring each tomcat instance to be configured without duplicate port numbers

vim /usr/local/tomcat/tomcat2/conf/server.xml
<Server port="8006" shutdown="SHUTDOWN">		#22行,修改Server prot,默认为8005 -> 修改为8006
<Connector port="8081" protocol="HTTP/1.1"		#69行,修改Connector port,HTTP/1.1  默认为8080 -> 修改为8081
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />	#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010

The first connector listens on port 8080 by default and is responsible for establishing HTTP connections. This connector is used when accessing the web application of the Tomcat server through a browser.
The second connector listens to port 8009 by default, and the AJP port is used by the container. For example, Apache can access Tomcat's port 8009 through the AJP protocol. 

 5. Modify the startup.sh and shutdown.sh files in each tomcat instance, and add tomcat environment variables

vim /usr/local/tomcat/tomcat1/bin/startup.sh 
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
##添加以下内容
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1

vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1


vim /usr/local/tomcat/tomcat2/bin/startup.sh 
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2

vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2

 6. Start /bin/startup.sh in each tomcat 

/usr/local/tomcat/tomcat1/bin/startup.sh 
/usr/local/tomcat/tomcat2/bin/startup.sh 

netstat -natp | grep java

 7. Browser access test

http://192.168.231.100:8080

 http://192.168.231.100:8081

Five: Tomcat optimization

The default configuration of Tomcat installed by default is not suitable for the production environment. It may frequently experience suspended animation and need to be restarted. Only through continuous stress testing and optimization can it run at the highest efficiency and stably. Optimization mainly includes three aspects,
namely operating system optimization (kernel parameter optimization), Tomcat configuration file parameter optimization, and Java virtual machine (JVM) tuning.

1. Tomcat configuration file parameter optimization

【redirectPort】如果某连接器支持的协议是HTTP,当接收客户端发来的HTTPS请求时,则转发至此属性定义的 8443 端口。

【maxThreads】Tomcat使用线程来处理接收的每个请求,这个值表示Tomcat可创建的最大的线程数,即支持的最大并发连接数,默认值是 200。

【minSpareThreads】最小空闲线程数,Tomcat 启动时的初始化的线程数,表示即使没有人使用也开这么多空线程等待,默认值是 10。

【maxSpareThreads】最大备用线程数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。默认值是-1(无限制)。一般不需要指定。

【processorCache】进程缓冲器,可以提升并发请求。默认值是200,如果不做限制的话可以设置为-1,一般采用maxThreads的值或者-1。

【URIEncoding】指定 Tomcat 容器的 URL 编码格式,网站一般采用UTF-8作为默认编码。

【connnectionTimeout】网络连接超时,单位:毫秒,设置为 0 表示永不超时,这样设置有隐患的。通常默认 20000 毫秒就可以。

【enableLookups】是否反查域名,以返回远程主机的主机名,取值为:true 或 false,如果设置为 false,则直接返回 IP 地址,为了提高处理能力,应设置为 false。

【disableUploadTimeout】上传时是否使用超时机制。应设置为 true。

【connectionUploadTimeout】上传超时时间,毕竟文件上传可能需要消耗更多的时间,这个根据你自己的业务需要自己调,以使Servlet有较长的时间来完成它的执行,
需要与上一个参数一起配合使用才会生效。

【acceptCount】指定当所有可以使用的处理请求的线程数都被使用时,可传入连接请求的最大队列长度,超过这个数的请求将不予处理,默认为 100 个。

【maxKeepAliveRequests】指定一个长连接的最大请求数。默认长连接是打开的,设置为1时,代表关闭长连接;为-1时,代表请求数无限制

【compression】是否对响应的数据进行GZIP压缩,off:表示禁止压缩;on:表示允许压缩(文本将被压缩)、force:表示所有情况下都进行压缩,默认值为 off,
压缩数据后可以有效的减少页面的大小,一般可以减小 1/3 左右,节省带宽。

【compressionMinSize】表示压缩响应的最小值,只有当响应报文大小大于这个值的时候才会对报文进行压缩,如果开启了压缩功能,默认值就是 2048。

【compressableMimeType】压缩类型,指定对哪些类型的文件进行数据压缩。

【noCompressionUserAgents="gozilla, traviata"】对于以下的浏览器,不启用压缩
#如果已经进行了动静分离处理,静态页面和图片等数据就不需做 Tomcat 处理,也就不要在 Tomcat 中配置压缩了。
vim /usr/local/tomcat/conf/server.xml
......
<Connector port="8080" protocol="HTTP/11.1" 
connectionTimeout="20000" 
redirectPort="8443" 
--71行--插入
minSpareThreads="50" 
enableLookups="false" 
disableUploadTimeout="true" 
acceptCount="300" 
maxThreads="500" 
processorCache="500"
URIEncoding="UTF-8" 
maxKeepAliveRequests="100"
compression="on" 
compressionMinSize="2048" 
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,image/gif,image /jpg,image/png"/>

/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh #参数修改后重启服务

 

 2. What is the default port of Tomcat and how to modify it

  1. Find the conf folder in the Tomcat directory
  2. Enter the conf folder and find the server.xml file
  3. Open the server.xml file
  4. Find the following information in the server.xml file
  5. Change the port 8080 of the Connector tab to the port you want
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

 3. Memory optimization (JVM optimization)

严重: Exception invoking periodic operation: java.lang.OutOfMemoryError: Java heap space  
严重: Error processing request java.lang.OutOfMemoryError: GC overhead limit exceeded 

Environmental specifications take 2C4G as an example

The configuration is added in catalina.sh under Tomcat's bin directory, before cygwin=false.

vim /usr/local/tomcat/bin/catalina.sh
......
JAVA_OPTS="$JAVA_OPTS -server -Xms2048m -Xmx2048m -Xmn768m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/tomcat/temp/oom.hprof -XX:ParallelGCThreads=2 -XX:PermSize=1024m -XX:MaxPermSize=1024m -Djava.awt.headless=true -XX:+DisableExplicitGC" 

cygwin=false
参数说明:
-server:一定要作为第一个参数,在多个CPU时性能佳

-Xms:堆内存的初始大小,是分配JVM的初始内存,默认为物理内存的1/64。一般来讲,此值设的大点,程序会启动的快一点。

-Xmx:堆内存的最大大小,是分配JVM的最大内存,默认为物理内存的1/4。如果程序运行需要占用更多的内存,超出了这个设置值,就会抛出OutOfMemory异常。
----------------------------------------------------
默认空余堆内存小于40%时,JVM就会增大堆直到-Xmx的最大限制;空余堆内存大于70%时,JVM会减少堆直到 -Xms的最小限制。
因此建议-Xms与-Xmx设成一样的值,均设为物理内存的一半。其目的是为了避免在java每次GC(垃圾回收机制清理堆区)后需要重新调整堆的大小而浪费资源。
----------------------------------------------------

-Xmn:堆内新生代的大小,通过这个值也可以得到老生代的大小:-Xmx减去-Xmn。官方推荐配置为整个堆的 3/8。
----------------------------------------------------
●堆区进一步细化分为:新生代、中生代、老生代。
●java中每新new一个对象所占用的内存空间就是新生代的空间,当java垃圾回收机制对堆区进行资源回收后,那些新生代中没有被回收的资源将被转移到中生代,中生代的被转移到老生代。
●整个JVM堆大小 = 新生代大小 + 老生代大小 + 永久代大小
----------------------------------------------------

-Xss:设置每个线程可使用的内存大小,即栈的大小。一般情况下,设置256k就足够了,此配置将会影响此进程中并发线程数的大小。

-XX:ParallelGCThreads:配置并行收集器的线程数,即:同时有多少个线程一起进行垃圾回收。当 CPU 数量小于8,此值建议配置等于 CPU 数量。

-XX:PermSize:设置非堆内存初始值,即持久代内存大小,默认是物理内存的1/4

-XX:MaxPermSize:最大非堆内存的大小,即最大持久代内存大小,默认是物理内存的1/4
----------------------------------------------------
●非堆区内存是不会被java垃圾回收机制进行处理的,且最大堆内存与最大非堆内存的和不能超出操作系统的可用内存。
●XMX和XMS设置一样大,MaxPermSize和MinPermSize设置一样大,这样可以减轻伸缩堆大小带来的压力。
----------------------------------------------------

-XX:+HeapDumpOnOutOfMemoryError:表示当JVM发生OOM时,自动生成DUMP文件

-XX:HeapDumpPath:表示生成DUMP文件的路径

-XX:+UseParNewGC:对新生代采用多线程并行回收,缩短垃圾收集的时间

-XX:+UseConcMarkSweepGC:并发标记清除收集器,它是老年代的收集算法,缩短垃圾收集的时间

-XX:+DisableExplicitGC:禁止调用System.gc(),防止误调用gc方法导致系统的 JVM 大起大落而使系统响应时间严重降低。

-Djava.awt.headless=true:免避在 Linux/Unix 环境下 Web 网页不能正常显示图片

-XX:+CMSParallelRemarkEnabled:启用并行标记,降低标记停顿

-XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0:这两个参数默认值就是这样的,表示触发FullGC时压缩堆,优化内存碎片

-XX:CMSInitiatingOccupancyFraction=70:在应用程序使用70%完内存后开始CMS垃圾收集

verify:

  设置成功后我们可以利用JDK自带的工具进行验证,这些工具都在JAVA_HOME/bin目录下:

​    1)jps:用来显示本地的java进程,以及进程号,进程启动的路径等。

​    2)jmap:观察运行中的JVM 物理内存的占用情况,包括Heap size , Perm size [下载地址](http://item.taobao.com/item.htm?id=41222768202) 等。

​    进入命令行模式后,进入JAVA_HOME/bin目录下,然后输入jps命令:
jps
#显示以下结果
2340 Bootstrap
6696 Jps

其中 Bootstrap进程就是我们启动了的 Tomcat,其进程号为2340.

​然后我们利用 jmap工具查看其内存相关配置:

jmap -heap 2340
#显示以下结果 Attaching to process ID 2340, please wait… Debugger attached successfully. Server compiler detected. JVM version is
24.65-b04 using thread-local object allocation. Parallel GC with 4 thread(s)


若内存不足,显示500错误,一般调整Xms和Xmx,可以将Xms和Xmx设置成一样

使用:set JAVA_OPTS=-Xms512m-Xmx512m

Guess you like

Origin blog.csdn.net/A1100886/article/details/131046401