?? threadpoolutil.java
字號:
package jxtamessenger.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
public class ThreadPoolUtil {
private static final Logger LOG = Logger.getLogger(ThreadPoolUtil.class.getName());
private static final int WAIT_EXISTING_TASKS_TERMINATE = 1;
private static final int WAIT_TASKS_RESPOND_CANCELLED = 1;
public static void shutdownAndAwaitTermination(ExecutorService pool) {
pool.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(WAIT_EXISTING_TASKS_TERMINATE, TimeUnit.SECONDS)) {
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(WAIT_TASKS_RESPOND_CANCELLED, TimeUnit.SECONDS))
LOG.warning("Pool did not terminate");
}
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted
pool.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -