提交 7b0a613c 编写于 作者: 武汉红喜's avatar 武汉红喜

CompletableFuture

上级 b3ea4cf2
......@@ -3,6 +3,9 @@ package org.hongxi.whatsmars.spring.boot.async;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* Created by shenhongxi on 2018/5/8.
*/
......@@ -10,7 +13,8 @@ import org.springframework.stereotype.Service;
public class MessageService {
@Async
public void send(String message) {
public CompletableFuture<String> send(String message) {
System.out.println(message);
return CompletableFuture.completedFuture(message);
}
}
......@@ -29,7 +29,7 @@ public class InitRunner implements CommandLineRunner {
userMapper.createIfNotExistsTable();
for (int i = 0; i < 10; i++) {
messageService.send("message" + i);
logger.info("send result: {}", messageService.send("message" + i).get());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册