Spring's quartz timer repeats two times at the same time to resolve the recent use of the Spring quartz timer, and when the time is found, the task is always repeated two times, under Tomcat or JBoss. Print out their hashcode, found to be different, that is, when the Web container is started, the two quartz threads are restarted repeatedly. Research down found that quartz does load two times: first: When the Web container starts, it is loaded once when the Applicationcontext.xml file is read. Second time: Spring itself will load applicationcontext.xml once. And my quartz configuration is written in the Applicationcontext.xml file. The solution is simple first extract the quartz configuration information and save it as a single file, such as ApplicationContext - Quartz.xml then modifies web. XML so that it can load the file when it is started so that the quartz will only load once when the Web container starts, and spring will no longer load. The Web. XML is configured as follows: <context-param> <param-name>contextConfigLocation</param-name> <param-value>/web-inf/ Classes/applicationcontext.xml,/web-inf/classes/applicationcontext-timertask.xml</param-value> </ Context-param> <!--turn on Monitor-<listener> <listener-class>Org.springframework.web.context.ContextLoaderListener</listener-class> </listener>The configuration of the timer is written in a separate configuration file, which is loaded only once when the Web container is started. This problem will also appear under Spring's TimerTask timer, as is the solution. I hope to help you heroes-------------------------------------------------------------------------------------------------------------- --------------reference above. -----------------------------------------------------------spring-scheduler.xml:<?xmlversion="1.0"encoding="UTF-8"? ><beans xmlns="Http://www.springframework.org/schema/beans"Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"Xmlns:context="Http://www.springframework.org/schema/context"Xmlns:jdbc="Http://www.springframework.org/schema/jdbc"Xmlns:jee="Http://www.springframework.org/schema/jee"xmlns:tx="Http://www.springframework.org/schema/tx"XMLNS:AOP="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"XMLNS:JPA="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPA"xsi:schemalocation="http//Www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp//Www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp//Www.springframework.org/schema/jdbchttp://www.springframework.org/schema/jdbc/spring-jdbc.xsdhttp//Www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee.xsdhttp//Www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOPhttp://www.springframework.org/schema/aop/spring-aop.xsdhttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/DATA/JPAhttp://www.springframework.org/schema/data/jpa/spring-jpa.xsd" default-lazy-init="false"> <!--Task Manager--<beans> <!--work class to invoke--<bean id="Quartzjob" class="Com.xinwei.util.UpdateCurrentValueTask"></bean> <!--define methods for calling objects and calling objects multiple task definitions multiple--<bean id="Jobtask2" class="Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--called Class-<property name="TargetObject"> <refbean="Quartzjob"/> </property> <!--calling methods in classes--<property name="Targetmethod"> <value>doTask</value> </property> </bean> <!-- Define trigger Time-<bean id="doTime2" class="Org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="Jobdetail"> <refbean="Jobtask2"/> </property> <!--cron expression runs one time 24:00 every day--<property name="cronexpression"Value="0 0 0 * *?"/> </bean> <!--general Management class if the lazy-init='false'Then the container starts executing the scheduler--<bean id="Startquertz"lazy-init="false"Autowire="No" class="Org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <refbean="doTime2"/> </list> </property> </bean> </beans></beans>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"version="2.5"> <display-name>security</display-name> <context-param> <param-name>contextco Nfiglocation</param-name> <param-value>Classpath*:/Applicationcontext.xml, Classpath*:/applicationcontext-shiro.xml, classpath *:/spring-scheduler.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!--main registration request, GET request object in normal class--<listener> <listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-va lue>utf-8</param-value> </init-param> <init-param> <param-name>forceenco Ding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-nam E>encodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--filter parameters, request the parameters transmitted from the foreground. Page. Remove-<filter> <filter-name>ParameterFilter</filter-name> <filter-cl Ass>com.xinwei.filter.parameterfilter</filter-class> <init-param> <param-name> blacklisturl</param-name> <!--Configuring the blacklist URL means that the URL of the filter does not go order:1-<param-value> /js/**/css/**/styles/**/images/**/ plugins/**/fonts/**/login/timeout/logout /views/** </param-value> </init-param> <init-param> <param-n Ame>whitelisturl</param-name> <!--Configure the whitelist URL to indicate the URL of the go filter order:2--> <param-value> /** </param-value> </init-param> </filter> <filter-mapping> <FILTER-NAME>PARAMETERFILTER</FILTER-NAME&G T <url-pattern>/*</url-pattern> </filter-mapping> <!--pagination Filter-- <filter> <filter-name>PageFilter</filter-name> <filter-class>com.xinwei.fil ter. Pagefilter</filter-class> <init-param> <param-name>blacklisturl</param-name> ; <!--Configure the blacklist URL to indicate a URL that does not go filter order:1--<param-value></param-value> </init-param& Gt <init-param> <param-name>whiteListURL</param-name> <!--Configure the whitelist URL to indicate the URL of the go filter order:2--> ; <param-value>/**/List</param-value> </init-param> </filter> <filter-mapping> <filter-nam E>pagefilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--<filter> <filter-name& Gt;openentitymanagerinviewfilter</filter-name> <filter-class> Org.springframework.orm.jpa.support.openentitymanagerinviewfilter</filter-class> </filter> <filte R-mapping> <filter-name>openEntityManagerInViewFilter</filter-name> <url-pattern>/*</url -pattern> </filter-mapping> <filter> <filter-name>shirofilter</filter-name> ; <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> ; <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>shirofilter</filt Er-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springservlet</servlet- Name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> & Lt;init-param> <param-name>contextConfigLocation</param-name> <param-value >classpath*:/spring-mvc.xml</param-value> </init-param> <init-param> <param-name>dispatchOptionsRequest</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <serv Let-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>/</url-pa ttern> </servlet-mapping> <servlet> <servlet-name>hessianServlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name> Contextconfiglocation</param-name> <param-value>classpath:/server/hessian-server.xml</ param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hessianServlet</servlet-name> <url-pattern>/hessian /*</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</se ssion-timeout> </session-config> <error-page> <EXCEPTION-TYPE>JAVA.LANG.THROWABLE&L T;/exception-type> <location>/WEB-INF/views/error/500.jsp</location> </error-page> <error-page> <error-code>500</error-code> <LOCATION>/WEB-INF/VIEWS/ERROR/500.J Sp</location> </error-page> <error-page> <error-code>404</error-code> <LOCATION>/WEB-INF/VIEWS/ERROR/4 04.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/WEB-INF/views/error/403.jsp</location> </error-page></web-app>
Spring's quartz timer repeats two times for problem resolution