import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Utility for switching threads
*
*/
public class ThreadUtils {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ThreadUtils.class);
public static final int CORES = Runtime.getRuntime().availableProcessors();
/**
if (!pool.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS)) {
List<Runnable> leftovers = pool.shutdownNow(); // Cancel currently executing tasks
if (!leftovers.isEmpty())
- System.err.println("Thread pool '" + pool.toString() + "' contained " + leftovers.size() + " tasks at forced shutdown: " + leftovers);
+ LOGGER.warn("Thread pool '" + pool.toString() + "' contained " + leftovers.size() + " tasks at forced shutdown: " + leftovers);
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(timeoutMs, TimeUnit.MILLISECONDS))
- System.err.println("Thread pool '" + pool.toString() + "' did not terminate");
+ LOGGER.warn("Thread pool '" + pool.toString() + "' did not terminate");
}
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted