O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The @Asynchronous policy

Making an operation asynchronous is as simple as the following:

@Asynchronouspublic Future<Connection> service() throws InterruptedException {  Connection conn = new Connection() {    {      Thread.sleep(1000);    }     @Override    public String getData() {      return "service DATA";    } }; return CompletableFuture.completedFuture(conn);}

The only constraint is to have the @Asynchronous method return Future or CompletionStage; otherwise, the implementation should throw an exception.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required