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