springタイマーが起動する原因と解決


調べた解決策をまとめます.
誘発原因:タイマーが二回起動され、二つのタイマースレッドが再起動されました.
          初めて:web容器を起動する時に、appication Contact.xmlファイルを読み込む時に、一回ロードします.
          第二回:Spring自体はappication Contact.xmlを1回ロードします.
          根源タイマーの配置と他のspringの配置は全部appication Contect.xmlファイルに書いてあります.
問題を残す:
      web容器でspringプロファイルを読み込む時は、どのようにして最初のロードタイマーを行いますか?
ソリューション:
     1,プログラム設定フラグ変数により変更されました.このような方式は提案されません.根本的に問題を解決できません.紹介しません.
     2,springメインプロファイルからタイマー構成を分離し、サブローディングを行うタイミング機能はウェブコンテナのみでローディングされます.
設定ファイルのサンプルは以下の通りです.
web.xmlプロファイルは主に部分に関連しています.
<context-param>
		<param-name>contextConfigLocation</param-name>
		<!--spring     -->
		<param-value>classpath:springConf/applicationContext.xml,
		<!--Quartz         quartz   -->
		classpath:springConf/timerQuartz-Context.xml,
		<!--timer         spring timer   -->			 
		classpath:springConf/timertask-Context.xml</param-value> 
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<display-name>springDispacher</display-name>
		<servlet-name>springDispacher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:springConf/applicationContext.xml</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springDispacher</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
主なspringプロファイルでは、aplication Contect.xmlを説明します.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
	<import resource="datasource-Context.xml" />
	<import resource="user-Context.xml" />
	<import resource="app-Context.xml" />
	<!--              import           -->
	<!--<import resource="timertask-Context.xml"/> -->
	<!--<import resource="timerQuartz-Context.xml"/> -->
</beans>
順調にタイマーの配置を復習します.
springにおけるtimerタイマーの配置方法

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!--        -->
	<bean id="timerTask" class="business.timertask.action.TimerTaskAction">
		<property name="taskService" ref="taskService"></property>
	</bean>
	<!--aop    	-->
	<bean id="taskServiceAop" parent="serviceAop">
		<property name="target" ref="taskService"></property>
	</bean>
	<!--        -->
	<bean id="taskService" class="business.timertask.services.IMPTaskService">
		<property name="taskDao" ref="taskDao"></property>
	</bean>
    <!--     dao 	-->
	<bean id="taskDao" class="business.timertask.dao.IMPTaskDAO">
		<property name="dataSource" ref="dataSource"></property>
		<property name="sqlMapClient" ref="sqlMapClient"></property>
	</bean>
	<!--       -->
	<bean id="start" class="org.springframework.scheduling.timer.TimerFactoryBean">
		<property name="scheduledTimerTasks">
			<list>
				<ref bean="scheduledTask" />
			</list>
		</property>
	</bean>
	<!--         -->
	<bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
		<!--  2   		-->
		<property name="delay">
			<value>2000</value>
		</property>
		<!-- 3      		-->
		<property name="period">
			<value>300000</value>
		</property>
		<property name="timerTask" ref="timerTask"></property>
	</bean>
</beans>
quartzタイマーの設定方法:timerQuartz-Coontext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
	<!--       -->
	<bean id="schedulerFactory" class="org.quartz.impl.StdSchedulerFactory">
	</bean>
	<!--      -->
	<bean id="cronExc" class="org.quartz.CronExpression">
		<constructor-arg>
			<value>0/5 * * * * ?</value>
		</constructor-arg>
	</bean>
	<!--          -->
	<bean id="cronTrigger" class="org.quartz.impl.triggers.CronTriggerImpl">
		<!--     -->
		<property name="name" value="cronTrigger" />
		<!--     -->
		<property name="group" value="cronTriggerGroup" />
		<!--       , 5    -->
		<property name="cronExpression">
			<value>0/5 * * * * ?</value>
		</property>
	</bean>
	<!--      job -->
	<bean id="customJob" class="business.timerTaskForQuatz.bean.CustomJob">
	</bean>
	<!--jobDetail  -->
	<bean id="jobDetail" class="org.quartz.impl.JobDetailImpl">
		<!--jobDetail    -->
		<property name="name" value="cornJob" />
		<!--jobDetail   -->
		<property name="group" value="cornJobGroup" />
		<!--      job classname -->
		<property name="jobClass" value="business.timerTaskForQuatz.bean.CustomJob" />
	</bean>
	<!--quartz   -->
	<bean id="quartzAction" class="business.timerTaskForQuatz.action.QuartzAction"
		init-method="start">
		<!--jobDetail  -->
		<property name="jobDetail" ref="jobDetail"></property>
		<!--      -->
		<property name="cronExpression" ref="cronExc"></property>
		<!--    -->
		<property name="sFactory" ref="schedulerFactory"></property>
		<!--    -->
		<property name="cronTrigger" ref="cronTrigger"></property>
	</bean>
</beans>
プロジェクトのソースコード
jarパッケージの添付図を一覧表示します.