Ich schrieb ein einfaches Beispiel zu CompletableFuture zu verstehen. Aber wenn ich es auf der Konsole drucke. Es zeigen irgendwann nur „asyn Demo“ Dies ist mein CodeZeige falsche Daten mit Java 8 CompleableFuture
public class DemoAsyn extends Thread {
public static void main(String[] args) {
List<String> mailer = Arrays.asList("[email protected]", "[email protected]", "[email protected]", "[email protected]",
"[email protected]");
Supplier<List<String>> supplierMail =() -> mailer;
Consumer<List<String>> consumerMail = Mail::notifyMessage;
Function<List<String>,List<String>> funcMail = Mail::sendMessage;
CompletableFuture.supplyAsync(supplierMail).thenApply(funcMail).thenAccept(consumerMail);
System.out.println("asyn demo");
}
}
public class Mail {
public static List<String> sendMessage(List<String> notifies) {
notifies.forEach(x -> System.out.println("sent to " + x.toString()));
return notifies;
}
public static void notifyMessage(List<String> notifies) {
notifies.forEach(x -> System.out.println("notified to " + x.toString()));
}
}