001/*
002 * Copyright 2002-2019 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.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025/**
026 * Annotation that marks a method as a candidate for <i>asynchronous</i> execution.
027 * Can also be used at the type level, in which case all of the type's methods are
028 * considered as asynchronous. Note, however, that {@code @Async} is not supported
029 * on methods declared within a
030 * {@link org.springframework.context.annotation.Configuration @Configuration} class.
031 *
032 * <p>In terms of target method signatures, any parameter types are supported.
033 * However, the return type is constrained to either {@code void} or
034 * {@link java.util.concurrent.Future}. In the latter case, you may declare the
035 * more specific {@link org.springframework.util.concurrent.ListenableFuture} or
036 * {@link java.util.concurrent.CompletableFuture} types which allow for richer
037 * interaction with the asynchronous task and for immediate composition with
038 * further processing steps.
039 *
040 * <p>A {@code Future} handle returned from the proxy will be an actual asynchronous
041 * {@code Future} that can be used to track the result of the asynchronous method
042 * execution. However, since the target method needs to implement the same signature,
043 * it will have to return a temporary {@code Future} handle that just passes a value
044 * through: e.g. Spring's {@link AsyncResult}, EJB 3.1's {@link javax.ejb.AsyncResult},
045 * or {@link java.util.concurrent.CompletableFuture#completedFuture(Object)}.
046 *
047 * @author Juergen Hoeller
048 * @author Chris Beams
049 * @since 3.0
050 * @see AnnotationAsyncExecutionInterceptor
051 * @see AsyncAnnotationAdvisor
052 */
053@Target({ElementType.TYPE, ElementType.METHOD})
054@Retention(RetentionPolicy.RUNTIME)
055@Documented
056public @interface Async {
057
058        /**
059         * A qualifier value for the specified asynchronous operation(s).
060         * <p>May be used to determine the target executor to be used when executing
061         * the asynchronous operation(s), matching the qualifier value (or the bean
062         * name) of a specific {@link java.util.concurrent.Executor Executor} or
063         * {@link org.springframework.core.task.TaskExecutor TaskExecutor}
064         * bean definition.
065         * <p>When specified on a class-level {@code @Async} annotation, indicates that the
066         * given executor should be used for all methods within the class. Method-level use
067         * of {@code Async#value} always overrides any value set at the class level.
068         * @since 3.1.2
069         */
070        String value() default "";
071
072}