TomcatThe server is a free open-source Web Application Server. The latest version is 6.x, which improves performance much compared with 5.x. It mainly optimizes memory usage, enhances Io capability, and reconstructs cluster functions.
I have recently made an in-depth study of Tomcat 6.x. Refer to the Tomcat full strategy described in the above statement. Since I wrote it for Tomcat 4.x in 2001, I have also summarized it for Tomcat 6.x to form this learning note, I hope it will be helpful to those who want to learn. This article covers Tomcat directory and server. XML Element Description: database connection pool configuration, thread pool configuration, and virtual directory configuration. For details about how to download, install, and run tomcat, please google.
The directory structure of Tomcat is as follows:
Directory Name |
Introduction |
Bin |
Store startup and shutdown Tomcat scripts |
Conf |
Contains different configuration files, server. XML (main configuration file of Tomcat) and Web. xml |
Work |
Store the class files generated after JSP Compilation |
Webapp |
Store the application example. The application you want to deploy will also be placed in this directory. |
Logs |
Store log files |
Lib |
These three directories mainly store the jar files required by Tomcat |
Server. xml configuration overview
Element name |
Attribute |
Explanation |
Server |
Port |
Specifies a port to listen for requests to disable tomcat. |
Shutdown |
Specifies the command string sent to the port |
Globalnamingresources |
|
The global JNDI resource of the server, which can have sub-tags <resource> </resource> |
Executor (thread pool, which can be shared by one or more connectors) |
Name |
Thread Pool name, which must be unique |
Nameprefix |
The thread name prefix, used to mark the thread name, so that each thread adds the thread number with this prefix, such as catalina-exec-1, catalina-exec-2 |
Maxthreads |
The maximum number of threads allowed in the thread pool. The default value is 200. High concurrency should be set to a higher value. It is only a limit and does not occupy resources. |
Minsparethreads |
The minimum number of threads that remain active. The default value is 25. This should be adjusted based on the load. Too small will affect the response speed, too large to occupy resources in vain |
Maxidletime |
The minimum number of threads that remain active. The default value is 25. This should be adjusted based on the load. Too small will affect the response speed, too large to occupy resources in vain |
Threadpriority |
The thread level. The default value is thread. norm_priority. |
Service |
Name |
Service name |
Connector (indicating the connection between the client and the Service) |
Port |
Specify the port number to be created on the server and listen to requests from the client at this break. |
Minprocessors |
Number of threads created when the server is started to process requests |
Maxprocessors |
Maximum number of threads that can be created to process requests |
Enablelookups |
If the value is true, you can call request. getremotehost () for DNS query to obtain the actual Host Name of the remote client. If the value is false, no DNS query is performed, but the IP address is returned. |
Redirectport |
Specifies the port number to be redirected after the server receives an SSL transfer request when processing an HTTP request. |
Acceptcount |
Specify the number of threads that can be used to process requests, and the number of requests that can be placed in the processing queue. Requests that exceed this number will not be processed. |
Connectiontimeout |
Time-out period (in milliseconds) |
Engine (indicates the request processing machine in the specified service to receive and process requests from ctor) |
Name |
|
Defaulthost |
Specifies the default host name for processing requests. It must be at least the same as the name attribute value of one of the host elements. |
Jvmroute |
|
Host (represents a virtual host and can contain context sub-nodes to configure virtual directories) |
Name |
Specify the Host Name |
Appbase |
The basic application directory, that is, the directory where the application is stored. |
Unpackwars |
If this parameter is set to true, Tomcat automatically decompress the war file. Otherwise, the application is directly run from the war file. |
Autodeploy |
Automatic deployment |
Xmlvalidation |
Verify XML |
Xmlnamespaceaware |
|
Realm (indicates the database that stores the user name, password, and role) |
Classname |
Specifies the class name used by realm. This class must implement the org. Apache. Catalina. realm Interface |
Context (configure virtual directory for the host subnode) |
Path |
Virtual directory name |
Docbase |
Physical path |
Debug |
Debug mode |
Reload |
True: Reload. It is automatically loaded after modification. |
The meanings of server. XML elements are described above. The following is a detailed example.
The Tomcat database connection pool is configured as follows:
Server. xml configure Resource
XML Code
- <Resource Name = "JDBC/exampledb" auth = "Container" type = "javax. SQL. datasource"
- Maxactive = "100" maxidle = "30" maxwait = "10000"
- Username = "app" Password = "app" driverclassname = "org. Apache. Derby. JDBC. clientdriver"
- Url = "JDBC: Derby: // localhost: 1527/springside-example; Create = true"/>
Added the context. xml file:
XML Code
- <Watchedresource> WEB-INF/Web. xml </watchedresource>
- <Resourcelink name = "JDBC/exampledb" Global = "JDBC/exampledb" type = "javax. SQL. datasource"/>
Tomcat shared thread pool Configuration:
Cancel the executor comment and modify the number of connections to an appropriate value.
XML Code
- <Executor name = "tomcatthreadpool" nameprefix = "Catalina-Exec -"
- Maxthreads = "200" minsparethreads = "100" maxidletime = "60000"/>
Executor = "tomcatthreadpool" indicates that this connection uses the connection pool named tomcatthreadpool configured above. If the connection pool does not take effect for a non-attribute shared connection, Protocol indicates that the http port number is 8080.
Java code
- <Connector Port = "8080" protocol = "HTTP/1.1" redirectport = "8443"
- Connectiontimeout = "20000"
- Executor = "tomcatthreadpool"
- Acceptcount = "100"
- Usebodyencodingforuri = "true"
- Enablelookups = "false"
- />
Virtual directory Configuration:
Add the following between
<! -- Configure the virtual directory, for example, http: // localhost: 8080 -->
XML Code
- <Context Path = "/" docbase = "D: \ workspace \ code \ hbloud \ Web"> </context>
The attachment is taken from springside3 and tomcat production config configuration example, that is, tomcat configuration in the production environment
Tomcat6.0 directory and server. xml