我正在制作一个弹簧项目并注册调度程序, 但是四个过程重叠执行。
的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 "%r" %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 :(得分: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"/>
这将每5秒执行一次'yourMethod'方法。它使用自己的线程,因此无需担心重叠.'com.package.location'是您的类所在的包地址。