تخطَّ إلى المحتوى

Leaked concurrency handle (ARCH4085)

هذا المحتوى غير متوفر بلغتك بعد.

Key java.performance.leaked-concurrency-handle · Severity warning · Category performance

A pool created with Executors.newFixedThreadPool and never shutdown() keeps non-daemon threads alive and prevents the JVM from exiting.

public void run(List<Task> tasks) {
ExecutorService pool = Executors.newFixedThreadPool(4);
tasks.forEach(pool::submit);
}
public void run(List<Task> tasks) {
ExecutorService pool = Executors.newFixedThreadPool(4);
try {
tasks.forEach(pool::submit);
} finally {
pool.shutdown();
}
}

Shut down created executor pools with shutdown() in a finally block or try-with-resources.