Thread Without Join (ARCH4041)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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.
Incorrect
Section titled “Incorrect”void load() { Thread t = new Thread(this::fetch); t.start(); // no join} // method returns before work finishesCorrect
Section titled “Correct”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.