In this code, I have two methods using vavr library. From this library I am using Future with the method andThen, this method run when the future has been completed, and this is synchronous, but when the thread call to the method "printTime" in this method, all program stop, and the test is success. this is the method
public void printTime(String m){
String pattern = "HH:mm:ss:SSS";
SimpleDateFormat formato = new SimpleDateFormat(pattern);
Date date = new Date();
String dateString = formato.format(date);
String retorno = dateString+" "+m;
System.out.println(retorno);
}
and this is the test
@Test
public void futuroAndThen() {
Future<String> f1 = Future.of(()->"Julian");
Future<String> f2 = Future.of(()->"Carvajal");
Future<String> f3 = Future.of(()->"Montoya");
Future<String> fResult = f3.andThen(x-> {
System.out.println(x.get());
System.out.println(Thread.currentThread().getName());
printTime("andThen2"+Thread.currentThread().getName());
}).andThen(y->{
System.out.println("y:"+y.get());
System.out.println(Thread.currentThread().getName());
f2.andThen(x->{
System.out.println("f2: "+x.get());
System.out.println("thread f2 "+Thread.currentThread().getName());
});
printTime("andThen2"+Thread.currentThread().getName());
});
}
finally the result within method printTime is:
Montoya
pool-1-thread-3
y:Montoya
pool-1-thread-1
f2: Carvajal
thread f2 pool-1-thread-3
and with the method is:
Montoya
pool-1-thread-1
but some moments the console is empty.
thank you very much :)