2015-10-05 37 views
0

我正在制作一个弹簧项目和注册调度程序, 但四个进程执行重叠。spring @Scheduled 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> 

server.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> 

我怎样可以安排只有一个任务? 请帮帮我; 我只想要一个任务调度器。

回答

0

试试这个link。它有很好的例子。 在你的.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"/> 

这将执行“yourMethod”的方法每隔5秒。它使用它自己的线程,所以不需要担心重叠.'com.package.location'是你的类所在的包地址。

相关问题