springmvc timing task starts multiple threads at the same time

1. Problem description:

Originally, a scheduled task will only create one thread to execute under a certain period of time.

However, the project on the server created 4 threads to execute, resulting in repeated creation of data.

2. Troubleshooting:

1, I checked the web.xml configuration of the project itself

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:config/applicationContext.xml</param-value>
</context-param>

<servlet>
  <servlet-name>springMVC</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:config/springMvc-servlet.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

Whether the configuration files in context-param and param-value under servlet are loaded repeatedly, causing multiple objects to be instantiated.

But the configuration of web.xml is not wrong.

2, I test the local code.

After testing the code locally, it was found that the scheduled task was created only once. So I suspect there is something wrong with the server configuration.

3. Find the cause of the problem:

The following is the service.xml configuration under the server-side tomcat, the configuration of the domain name

<Host name="www.xxx.com"  appBase="webapps"
       unpackWARs="true" autoDeploy="true">
<Context docBase="xxx" path="" reloadable="true"/>
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log" suffix=".txt"
          pattern="%h %l %u %t "%r" %s %b" />

 </Host>
  <Host name="xxx.com"  appBase="webapps"
       unpackWARs="true" autoDeploy="true">
<Context docBase="xxx" path="" reloadable="true"/>

   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log" suffix=".txt"
          pattern="%h %l %u %t "%r" %s %b" />

 </Host>

It is caused by the configuration of the appBase="" under the Host tag and the docBase="" attribute under the context tag.

The following is my personal understanding: appBase="webapps" means: the projects in this directory will be automatically deployed

docBase="" deploys the project under the specified path.

When the path under docBase and the project path in appBase are duplicated, they will be deployed twice, resulting in the creation of multiple threads when executing scheduled tasks.

But if this is the case, when my project path, which one is it actually accessing? And if it is deployed twice, but there is only one project folder under webapps, I don't understand.



My current solution: remove a host tag block, move the project to another path, modify the path of docBase (docBase is changed to absolute path).

Modify the (service.xml) part of the configuration as follows:

<Host name="www.xxx.com"  appBase="webapps"
       unpackWARs="true" autoDeploy="true">
<Context docBase="/hom/tomcat/xxx" path="" reloadable="true"/>
   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
          prefix="localhost_access_log" suffix=".txt"
          pattern="%h %l %u %t "%r" %s %b" />

 </Host>

The xxx in the absolute path is the project name


In addition, another bug was also solved by the way: javax.management.InstanceNotFoundException: com.alibaba.druid:type=DruidDataSourceStat

Ali's druid reports an error.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325731594&siteId=291194637