Spring @Async annotation on interface methods Spring @Async annotation on interface methods spring spring

Spring @Async annotation on interface methods


I quickly tested it and having @Async on an interface will make implementation asynchronous.

If you want to try it yourself: You can easily test this by checking that the values of Thread.currentThread().getId() are different (before calling the method and inside the method) or just adding a Thread.sleep(10000); in the method expected to be asynchronous.

Also take note the return type must be void or java.util.concurrent.Future.


Since @Async is defined as

@Target(value={TYPE,METHOD})@Retention(value=RUNTIME)@Documentedpublic @interface Async

and TYPE is

Class, interface (including annotation type), or enum declaration

and METHOD is

Method declaration

yes, you can use it on interface methods, too.