¿Cómo pedirle a CompletableFuture que use hilos no daemon?
He escrito el siguiente código:
System.out.println("Main thread:" + Thread.currentThread().getId());
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
try {
System.out.println("Before sleep thread:" + Thread.currentThread().getId(), + " isDaemon:" + Thread.currentThread().isDaemon());
Thread.sleep(100);
System.out.println("After sleep");
} catch (InterruptedException e) {
e.printStackTrace();
}
});
future.whenComplete((r, e) -> System.out.println("whenCompleted thread:" + Thread.currentThread().getId()));
y este imprime:
Main thread:1
Before sleep thread:11 isDaemon:true
y acabados.
¿Cómo puedo cambiar este comportamiento?
PD No veo nada relacionado enrunAsync
java doc