I am doing some experiments with the Java CompletableFuture. Here is the code
public class SpringBootAsyncApplication {
public static void main(String[] args) {
CompletableFuture.supplyAsync(() - > {
return MailUtil.getMailInfo();
}).thenAccept(content - > {
System.out.println("Mail content: " + content);
});
}
}
class MailUtil {
public static String getMailInfo() {
return "Your email content";
}
public static boolean sendMail() {
System.out.println("Send mail: completed");
return true;
}
public static void logging() {
System.out.println("Log: Send mail at " + System.currentTimeMillis());
}
}
I run the program 3 times. All of them didn't return any output ? But when I replace return MailUtil.getMailInfo();
with number 5
CompletableFuture.supplyAsync(() - > {
return 5;
}).thenAccept(content - > {
System.out.println("Mail content: " + content);
});
then it runs as normal. Why is that ?