Usage Environment: ECLIPSE+MAVEN+SPRING+QUARTZ1
Use purpose: Perform the timer to complete the scan operation.
Puzzle point: Using the QUARTZ2 version will appear inexplicable errors, similar to the interface and class definition of the difference. Look at the document and don't get it straight.
Use steps:
1. Configure the MAVEN profile (configured with the QUARTZ1 version), pom.xml add the code:
The code is as follows |
Copy Code |
<!--add Quartz frame--> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>1.8.5</version> </dependency> <!--components Optional--> <!--start--> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>commons-digester</groupId> <artifactId>commons-digester</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.8.3</version> </dependency> <!--end-->
2. Configure the Spring profile Spring.xml file to load the Quartz. configuration file with the following code: <!--: Using Methodinvokingjobdetailfactorybean, the task class can specify the calling method by Targetmethod without implementing the job interface--> <!--define methods in the target bean and bean--> <bean id= "Springqtzjob" class= "Com.founder.centerbusiness.controller.basicMgr.RuleMgrController"/> <bean id= "Springqtzjobmethod" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" > <property name= "TargetObject" > <ref bean= "Springqtzjob"/> </property> <property name= "Targetmethod" > <!--the name of the method to be executed--> <value>execute</value> </property> </bean> <!--======================== scheduling trigger ========================--> <bean id= "Crontriggerbean" class= "Org.springframework.scheduling.quartz.CronTriggerBean" > <property name= "Jobdetail" ref= "Springqtzjobmethod" ></property> <!--0/1 * * * *? : Perform a--> scan every second <property name= "cronexpression" value= "0/1 * * * *?" ></property> </bean> <!--======================== Dispatch factory ========================--> <bean id= "Springjobschedulerfactorybean" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= "Triggers" > <list> <ref bean= "Crontriggerbean"/> </list> </property> </bean> which <!--0/2 * * * *? : Perform a--> scan every second <property name= "cronexpression" value= "0/2 * * * *?" ></property> That's a scan every 1 seconds. <!--0/8 * * * *? : Perform a--> scan every 8 seconds <property name= "cronexpression" value= "0/8 * * * *?" ></property> That's a scan every 8 seconds. What is the meaning of the specific *, to ask the degree of the Empress. Id= "Springqtzjob" represents the local file path in which the action is performed. 3. Local execution Java file code is as follows: /** * Execution Timer */ protected void execute () { String currenttime = Dateutils.getdatetime (); System.out.println ("Current Time--->" + currenttime); } |
The code screenshot is as follows: