CompletableFuture también puede ejecutar métodos de forma asincrónica
1. Ejemplo de resultado sin devolución
final CompletableFuture <Void> future = CompletableFuture.runAsync (() -> { log.info ("返回 Void 的 CompletableFuture 操作 示例"); }). excepcionalmente (throwable -> { log.error (throwable.getMessage ()); return null; }); future.get (); RedisClientTest.log.info ("------- 结束 ---------");
2. Ejemplos de tipos básicos que regresan
final CompletableFuture <String> future = CompletableFuture.supplyAsync (() -> { return "返回 String 的 CompletableFuture 操作 示例"; }). excepcionalmente (throwable -> { log.info (throwable.getMessage ()); return "-1 "; }); Resultado final de la cadena = future.get (); log.info ("resultado:" + resultado);