2014-10-17 3 views
4

자바에서 자동으로 실행되도록 작업을 예약해야합니다. 나는 창 일정과 동일한 기능이 필요합니다. 나는 일일, 일년 내내 해왔지만 주간 일정에 왔을 때 붙어 있지 않습니다. 어떻게하는지. 자바 캘린더를 사용하고 있습니다. 좋은 해결책을 찾는데 도움을주십시오.자바 봄 MVC를 사용하여 작업 예약

어떤 도움이나 아이디어는 다음과 같이 봄에 작업이 4 가지 방법으로 수행 할 수있는 예약

+0

http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#scheduling-quartz는 읽을만한 가치가 있습니다. –

+0

Checkout [작업 실행 및 예약] (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html) 장 – ponomandr

답변

6

감지 할 수있을 것이다.

1. @Scheduled 주석의 고정 지연 속성을 사용하는 작업 스케줄링. 등록 정보 파일에서 크론 표현식을 사용하여 @Scheduled 주석

@Scheduled(cron = "*/5 * * * * ?") 
public void demoServiceMethod() { 
    System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date()); 
} 

3. 작업 스케줄링에서 크론 표현식을 사용하여

public class DemoServiceBasicUsageFixedDelay { 
    @Scheduled(fixedDelay = 5000) 
    // @Scheduled(fixedRate = 5000) 
    public void demoServiceMethod() { 
     System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date()); 
    } 
} 

2. 작업 스케줄링.

@Scheduled(cron = "${cron.expression}") 
public void demoServiceMethod() { 
    System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date()); 
} 

4. 작업 스케줄링 사용 크론 표현은 http://howtodoinjava.com/2013/04/23/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/

에 # 4

<task:scheduled-tasks> 
     <task:scheduled ref="demoServiceXmlConfig" method="demoServiceMethod" cron="#{applicationProps['cron.expression']}"></task:scheduled> 
</task:scheduled-tasks> 

자세한 설명은

public class DemoServiceXmlConfig { 
    public void demoServiceMethod() { 
     System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date()); 
    } 
} 

XML의 설정 상황에 맞는 구성으로 구성3210

희망이 도움이됩니다.