Apache Tomcat tips and tricks
1. How to change the Apache Tomcat port?
Edit the tomcat/conf/server.xml
configuration file.
The TCP port where the Servlet container will bind to accept plain HTTP requests is set in the Connector element:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2. How to run Apache Tomcat on two different ports?
To make the Servlet container accept plain HTTP requests on an additional port,
for example on port 8081, edit the tomcat/conf/server.xml
configuration file
and add a new
Connector
element:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" />
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000" />
Note, this will cause Tomcat to create one thread pool for each Connector
.
On Tomcat 10.1 by default the pool will have a minimum spare thread count of 25
and a max thread count of 200.
To modify the thread pool settings for the second Connector
:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" />
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
minSpareThreads="2"
maxThreads="25" />
To make the two Connector
s share a thread pool add an
Executor and
reference it like this:
<Executor name="sharedHttpThreadPool"
namePrefix="http-shared-exec-"
minSpareThreads="10"
maxThreads="200" />
<Connector port="8080" protocol="HTTP/1.1"
executor="sharedHttpThreadPool"
connectionTimeout="20000" />
<Connector port="8081" protocol="HTTP/1.1"
executor="sharedHttpThreadPool"
connectionTimeout="20000" />