2017-10-26 6 views
0

공휴일 제외 스케줄러 봄 작업을 실행하고 나는 주석내가 @EnableScheduling로 구성된 자바 작업을

@Scheduled(cron = "${job1.outgoingCron:0 45 15,18,20 * * MON-FRI}", zone = "America/New_York") 
public void Process() { 

} 

와 함께 작업을 실행할 수 있어요 그러나 나는 무엇 미국 휴일이 작업을 실행하지 않으 일정을 업데이트하는 가장 좋은 방법입니다.

답변

0

봅니다 예를 들어, CronTrigger 또는 사용자 정의 Trigger를 사용하여, 일정 explicitly을 설정합니다 :

@SpringBootApplication 
@EnableScheduling 
public class MyApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(MyApplication.class, args); 
    } 

    @Bean 
    public TaskScheduler taskScheduler() { 
     return new ThreadPoolTaskScheduler(); 
    } 
} 

@Component 
@RequiredArgsConstructor // Lombok annotation 
public class StartUp implements ApplicationRunner { 

    @NonNull private final TaskScheduler scheduler; 

    @Override 
    public void run(ApplicationArguments args) throws Exception { 

     // Variant 1 
     scheduler.schedule(this::myTask, new CronTrigger(/* your schedule */)); 

     // Variant 2 
     scheduler.schedule(this::myTask, this::myTriger); 
    } 

    private void myTask() { 
     //... 
    } 

    private Date myTrigger(TriggerContext triggerContext) { 
     //... 
    } 
}