0

春のプロジェクトを作ってスケジューラーを登録しているのですが、4つの処理が重複して実行されます。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="couchLogServer" version="2.5">
  <display-name>couchLogServer</display-name>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>


  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext_SqlMapClient.xml</param-value>
  </context-param>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>couchLogServer</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>couchLogServer</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>



</web-app>

サーバー.xml

<Engine defaultHost="localhost" name="Catalina">

      <Host appBase="webapps" autoDeploy="false" deployOnStartup="false" name="localhost" unpackWARs="true">

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

      <Context docBase="ROOT" path="/couchLogServer" reloadable="true" source="org.eclipse.jst.jee.server:couchLogServer"/></Host>
    </Engine>

タスクを 1 つだけスケジュールするにはどうすればよいですか? 私を助けてください; タスク スケジューラが 1 つだけ必要です。

4

1 に答える 1

0

このリンクを試してください。良い例があります。.xml 構成では、次のようにできます。

 <context:component-scan base-package="com.package.location" /> 

<task:scheduled-tasks scheduler="Scheduler">
    <task:scheduled ref="yourBean" method="yourMethod" fixed-delay="5000" />
</task:scheduled-tasks>


<task:scheduler id="myScheduler"/>

これにより、5 秒ごとに「yourMethod」メソッドが実行されます。独自のスレッドを使用するため、重複を心配する必要はありません。「com.package.location」は、クラスが配置されているパッケージ アドレスです。

于 2015-11-04T09:17:12.187 に答える