'Spring Async Annotation: Executor Id by Enum
I have a custom @Async annotation with the specified Executor ID.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Async("fixedThreadPool")
public @interface AsyncFixedPool {
}
I wonder is it possible to specify executor id by enum? For example, something like that.
public enum ExecutorType {
EXECUTOR_1, EXECUTOR_2
}
...
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Async
public @interface AsyncFixedPool {
// value converts as Enum.name()
@AliasFor(annotation = Async.class, attribute = "value")
ExecutorType value();
}
...
@AsyncFixedPool(EXECUTOR_1)
public void myAsyncMethod() {...}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
