Executor Service Leak (ARCH4040)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key java.async.executor-service-leak · Severity warning · Category async
An ExecutorService created via Executors.newFixedThreadPool and never shut down leaks non-daemon threads and can prevent the JVM from exiting.
Incorrect
Section titled “Incorrect”void run(List<Task> tasks) { ExecutorService pool = Executors.newFixedThreadPool(4); tasks.forEach(t -> pool.submit(t)); // never shut down}Correct
Section titled “Correct”void run(List<Task> tasks) { ExecutorService pool = Executors.newFixedThreadPool(4); try { tasks.forEach(pool::submit); } finally { pool.shutdown(); }}Shut the ExecutorService down with shutdown() in a finally block, or use try-with-resources.