public final class ThreadUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addShutdownHook(Runnable runnable) |
static void |
countDown(CountDownLatch latch) |
static int |
getSuitableThreadCount()
Through the number of cores, calculate the appropriate number of threads; 1.5-2 times the number of CPU cores.
|
static int |
getSuitableThreadCount(int threadMultiple)
Through the number of cores, calculate the appropriate number of threads.
|
static void |
latchAwait(CountDownLatch latch)
Await count down latch.
|
static void |
latchAwait(CountDownLatch latch,
long time,
TimeUnit unit)
Await count down latch with timeout.
|
static void |
shutdownThreadPool(ExecutorService executor) |
static void |
shutdownThreadPool(ExecutorService executor,
org.slf4j.Logger logger)
Shutdown thread pool.
|
static void |
sleep(long millis)
Sleep.
|
public static void sleep(long millis)
millis - sleep millisecondpublic static void countDown(CountDownLatch latch)
public static void latchAwait(CountDownLatch latch)
latch - count down latchpublic static void latchAwait(CountDownLatch latch, long time, TimeUnit unit)
latch - count down latchtime - timeout timeunit - time unitpublic static int getSuitableThreadCount()
public static int getSuitableThreadCount(int threadMultiple)
threadMultiple - multiple time of corespublic static void shutdownThreadPool(ExecutorService executor)
public static void shutdownThreadPool(ExecutorService executor, org.slf4j.Logger logger)
executor - thread poollogger - loggerpublic static void addShutdownHook(Runnable runnable)
Copyright © 2018–2024 Alibaba Group. All rights reserved.