Ir al contenido

Thread Without Join (ARCH4041)

Esta página aún no está disponible en tu idioma.

Key java.async.thread-without-join · Severity warning · Category async

When a thread is created and started but never joined, the spawning scope may exit before the thread completes, leaving its work and exceptions unobserved.

void load() {
Thread t = new Thread(this::fetch);
t.start(); // no join
} // method returns before work finishes
void load() throws InterruptedException {
Thread t = new Thread(this::fetch);
t.start();
t.join(); // wait for completion
}

Wait on the started thread with join(), or use an ExecutorService that manages the lifecycle.