All Products
Search
Document Center

:Configure Java Tomcat parameters

Last Updated:Sep 03, 2024

When you use a WAR package to deploy an application, you can customize Tomcat parameters, including the application port, application access path, and maximum number of threads, based on your business requirements. This topic describes how to configure Java Tomcat parameters in the SAE console for a Java application deployed by using a WAR package.

Prerequisites

Before you configure Java Tomcat parameters, make sure that the WAR package for the Java application is prepared.

Procedure

Configure Java Tomcat when you create an application

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click Create Application.

  3. In the Basic Information step, configure the parameters and click Next: Application Deployment Configurations.

  4. In the Deployment Configurations step, configure the application deployment information.

    ParameterDescription
    Technology Stack Programming LanguageSelect Java.
    Application Deployment MethodSelect Deployment with WAR Packages.
    Application Runtime Environment
    • apache-tomcat-XXX: This option is suitable for Spring Boot applications or Dubbo applications.
    • EDAS-Container-XXX: This option is suitable for high-speed service framework (HSF) applications.
    Java Environment
    • Dragonwell X (recommended): supports OpenJDK. If you select this option, the startup and runtime of the application are accelerated and garbage collection (GC) efficiency is improved. For more information, see Configure a startup command.

    • Open JDK X: This environment is based on the CentOS operating system and the size of the base image is large.

    • openjdk-XXXXX-jdk-alpine3.9: This environment is based on the Alpine operating system and the size of the base image is small.

    Note

    Compared with the CentOS operating system, the Java environment that is based on the Alpine operating system supports fewer tools or commands. If you select openjdk-XXXXX-jdk-alpine3.9, some commands in the webshell may fail to be run. Select an environment based on your business scenario.

    File Upload MethodSelect Upload WAR Package or WAR Package Address.
    • Upload WAR Package: Click Select File and select the WAR package that you want to use to deploy the application.
    • WAR Package Address: Enter the directory in which the WAR package is stored.
    Note The name of the package that you want to use to deploy an application can contain only letters, digits, hyphens (-), and underscores (_).
    VersionThe version number of the application. Enter a version number or click Use Timestamp as Version Number.
    Time Zone SettingsSelect the time zone of the application. Example: UTC+8.
  5. In the Java Tomcat Settings section, select Custom Configuration and click Edit.

    选中Java Tomcat

  6. In the Edit Java Tomcat Configuration panel, configure the parameters and click OK.

    image

    Parameter

    Description

    Application Port

    The port number used by the application. Valid values: 1024 to 49151. Default value: 8080.

    Tomcat Context

    The application access path. Valid values:

    • Package Name: The name of the WAR file is used. You do not need to configure this parameter. This setting is supported only if you set the File Upload Method parameter to Upload WAR Package.

    • Root Directory: The application access path is /.

    • Custom: Specify an application access path in the Custom Path field.

    Maximum Threads

    The maximum number of threads that concurrently process requests. Valid values: 10 to 1024. Default value: 400.

    Important

    The value of the Maximum Threads parameter affects the application performance. Exercise caution when you configure this parameter.

    Tomcat Encoding

    The encoding format for Tomcat. Valid values: UTF-8, ISO-8859-1, GBK, and GB2312. Default value: ISO-8859-1.

    Use Body Encoding for URL

    By default, this feature is enabled. In this case, you can use the character set of the HTTP request body to decode query parameters (QueryString).

  7. Click Next: Confirm Specifications.

  8. In the Specification Confirmation step, view the details of the application and the fee for the selected specifications. Then, click Confirm.

    The Creation Completed step appears. You can click Application Details to go to the Basic Information page to view the basic information of the application.

Configure Java Tomcat when you deploy an application

Warning

After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

The procedure that can be performed to update an application varies based on the number of instances in the application. This section provides an example on how to configure the required features for an application in which the number of instances is greater than or equal to 1. For information about how to update an application in which the number of instances is 0, see Update an application.

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click the name of the application that you want to manage.

  3. In the upper-right corner of the Basic Information page, click Deploy Application.

  4. In the Java Tomcat Settings section, select Custom Configuration and click Edit.

    选中Java Tomcat

  5. In the Edit Java Tomcat Configuration panel, configure the parameters and click OK.

    image

    Parameter

    Description

    Application Port

    The port number used by the application. Valid values: 1024 to 49151. Default value: 8080.

    Tomcat Context

    The application access path. Valid values:

    • Package Name: The name of the WAR file is used. You do not need to configure this parameter. This setting is supported only if you set the File Upload Method parameter to Upload WAR Package.

    • Root Directory: The application access path is /.

    • Custom: Specify an application access path in the Custom Path field.

    Maximum Threads

    The maximum number of threads that concurrently process requests. Valid values: 10 to 1024. Default value: 400.

    Important

    The value of the Maximum Threads parameter affects the application performance. Exercise caution when you configure this parameter.

    Tomcat Encoding

    The encoding format for Tomcat. Valid values: UTF-8, ISO-8859-1, GBK, and GB2312. Default value: ISO-8859-1.

    Use Body Encoding for URL

    By default, this feature is enabled. In this case, you can use the character set of the HTTP request body to decode query parameters (QueryString).

  6. After you configure the settings, click Confirm.

Modify a Java Tomcat configuration file by using a ConfigMap

If the preceding Java Tomcat parameters provided in the SAE console cannot meet your business requirements, or if you want to modify your Java Tomcat configuration file, you can create a ConfigMap.

After you deploy your application in SAE by using a WAR file, the server.xml file is saved in the /home/admin/apache-tomcat-8.5.42/conf directory. The example in this section uses the server.xml file to demonstrate how to modify a Java Tomcat configuration file by using a ConfigMap.

  1. Modify the server.xml file.

    1. Log on to the SAE console.

    2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click the name of an application.

    3. On the Basic Information page, click the Instance Deployment Information tab. In the Default Group section, click Webshell in the Actions column of the application.

    4. In the Webshell window, modify the content of the server.xml file and close the window.

      1. Run the following command to go to the directory where the server.xml file is saved.

        cd /home/admin/apache-tomcat-8.5.42/conf
      2. Run the following command to view the content of the server.xml file.

        cat server.xml
      3. Copy the content of the server.xml file to your on-premises computer, modify the content of the file based on your business requirements, and then copy the new content.

  2. Create a ConfigMap.

    Note

    The namespace of the ConfigMap that you want to create must be the same as the namespace of the application for which you want to create the ConfigMap.

    1. In the left-side navigation pane, click Namespaces. In the top navigation bar, select a region. Then, click the name of the namespace for the application.

    2. In the left-side navigation pane, click ConfigMaps. On the ConfigMaps page, click Create.

    3. In the Create ConfigMap panel, configure the parameters. Copy the new content of the server.xml file to the Value text box and click OK.

      sc_create_configmap_for_tomcatIn this example, the Method parameter is set to Manual. The following table describes the parameters. For more information, see Manage a Kubernetes ConfigMap.

      ParameterDescription
      ConfigMap NameEnter a name for the ConfigMap.
      ConfigMap DescriptionEnter a description for the ConfigMap.
      Configure Mappings
      • A key can contain up to 250 characters in length. A value can contain up to 10,000 characters in length.
      • You can specify up to 20 key-value pairs for a ConfigMap.

    After you create a ConfigMap, the ConfigMap is displayed on the ConfigMaps page.

  3. Deploy the application and mount the ConfigMap.

    1. In the left-side navigation pane, click Namespace Details. On the Namespace Details page, click the Resource Information tab.

    2. Click the value of Applications. On the Applications page, click the application that you want to deploy.

    3. In the upper-right corner of the Basic Information page, click Deploy Application.

    4. In the lower part of the Deploy Application page, click the Configuration Management section, select the ConfigMap and the Key that are configured in Step2, and then specify the Mount Path parameter.sc_mount_configuration_for_tomcat

    5. After you configure the parameters, click Confirm.

      You can go to the Change Records page to check the deployment status of the application.

Verify the results

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click the name of the application that you want to manage.

  3. Check whether the configurations have taken effect.

    • Method 1:

      In the left-side navigation pane of the Basic Information page, click Change Records. On the Change Records page, view the change details. If Executed is displayed in the Change Status column, the application is deployed and the configurations have taken effect.

    • Method 2:

      On the Basic Information page, click the Instance Deployment Information tab to view the Status of the instances. If Running is displayed in the Status column, the application is deployed and the configurations have taken effect.