001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.scheduling.annotation; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Repeatable; 022import java.lang.annotation.Retention; 023import java.lang.annotation.RetentionPolicy; 024import java.lang.annotation.Target; 025 026/** 027 * An annotation that marks a method to be scheduled. Exactly one of 028 * the {@link #cron()}, {@link #fixedDelay()}, or {@link #fixedRate()} 029 * attributes must be specified. 030 * 031 * <p>The annotated method must expect no arguments. It will typically have 032 * a {@code void} return type; if not, the returned value will be ignored 033 * when called through the scheduler. 034 * 035 * <p>Processing of {@code @Scheduled} annotations is performed by 036 * registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be 037 * done manually or, more conveniently, through the {@code <task:annotation-driven/>} 038 * element or @{@link EnableScheduling} annotation. 039 * 040 * <p>This annotation may be used as a <em>meta-annotation</em> to create custom 041 * <em>composed annotations</em> with attribute overrides. 042 * 043 * @author Mark Fisher 044 * @author Juergen Hoeller 045 * @author Dave Syer 046 * @author Chris Beams 047 * @since 3.0 048 * @see EnableScheduling 049 * @see ScheduledAnnotationBeanPostProcessor 050 * @see Schedules 051 */ 052@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) 053@Retention(RetentionPolicy.RUNTIME) 054@Documented 055@Repeatable(Schedules.class) 056public @interface Scheduled { 057 058 /** 059 * A cron-like expression, extending the usual UN*X definition to include triggers 060 * on the second as well as minute, hour, day of month, month and day of week. 061 * <p>E.g. {@code "0 * * * * MON-FRI"} means once per minute on weekdays 062 * (at the top of the minute - the 0th second). 063 * @return an expression that can be parsed to a cron schedule 064 * @see org.springframework.scheduling.support.CronSequenceGenerator 065 */ 066 String cron() default ""; 067 068 /** 069 * A time zone for which the cron expression will be resolved. By default, this 070 * attribute is the empty String (i.e. the server's local time zone will be used). 071 * @return a zone id accepted by {@link java.util.TimeZone#getTimeZone(String)}, 072 * or an empty String to indicate the server's default time zone 073 * @since 4.0 074 * @see org.springframework.scheduling.support.CronTrigger#CronTrigger(String, java.util.TimeZone) 075 * @see java.util.TimeZone 076 */ 077 String zone() default ""; 078 079 /** 080 * Execute the annotated method with a fixed period in milliseconds between the 081 * end of the last invocation and the start of the next. 082 * @return the delay in milliseconds 083 */ 084 long fixedDelay() default -1; 085 086 /** 087 * Execute the annotated method with a fixed period in milliseconds between the 088 * end of the last invocation and the start of the next. 089 * @return the delay in milliseconds as a String value, e.g. a placeholder 090 * @since 3.2.2 091 */ 092 String fixedDelayString() default ""; 093 094 /** 095 * Execute the annotated method with a fixed period in milliseconds between 096 * invocations. 097 * @return the period in milliseconds 098 */ 099 long fixedRate() default -1; 100 101 /** 102 * Execute the annotated method with a fixed period in milliseconds between 103 * invocations. 104 * @return the period in milliseconds as a String value, e.g. a placeholder 105 * @since 3.2.2 106 */ 107 String fixedRateString() default ""; 108 109 /** 110 * Number of milliseconds to delay before the first execution of a 111 * {@link #fixedRate()} or {@link #fixedDelay()} task. 112 * @return the initial delay in milliseconds 113 * @since 3.2 114 */ 115 long initialDelay() default -1; 116 117 /** 118 * Number of milliseconds to delay before the first execution of a 119 * {@link #fixedRate()} or {@link #fixedDelay()} task. 120 * @return the initial delay in milliseconds as a String value, e.g. a placeholder 121 * @since 3.2.2 122 */ 123 String initialDelayString() default ""; 124 125}