×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: digas
Added: Sep 26, 2014 2:51 PM
Views: 11
Tags: spring
  1. Step 1:
  2.  
  3. Add the task namespace and xsd schema to your application context
  4.  
  5.  
  6. <beans xmlns="http://www.springframework.org/schema/beans"
  7. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  8. xmlns:p="http://www.springframework.org/schema/p"
  9. xmlns:task="http://www.springframework.org/schema/task"
  10. xsi:schemaLocation="
  11. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  12. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  13. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
  14. Step 2:
  15.  
  16. Add the following couple of tags to your application context xml
  17.  
  18.  
  19. <task:annotation-driven scheduler="taskScheduler"/>
  20. <task:scheduler id="taskScheduler" pool-size="2"/>
  21. Step 3:
  22.  
  23. Annotate the function you need to be called whenever timer is reached
  24.  
  25.  
  26. @Service
  27. public class Job {
  28.     @Scheduled(fixedDelay=10000)
  29.     public void scheduledJob(){
  30.     System.out.println("Scheduled Job Triggered");
  31.    }
  32. }