public class ThreadUtil extends Object
| 构造器和说明 |
|---|
ThreadUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> ThreadLocal<T> |
createThreadLocal()
创建本地线程对象
|
static Runnable |
excAsync(Runnable runnable,
boolean isDeamon)
执行异步方法
|
static <T> Future<T> |
execAsync(Callable<T> task)
执行有返回值的异步方法
Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞 |
static void |
execute(Runnable runnable)
直接在公共线程池中执行线程
|
static StackTraceElement[] |
getStackTrace() |
static StackTraceElement |
getStackTraceElement(int i)
获得堆栈项
|
static <T> CompletionService<T> |
newCompletionService()
新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。
|
static <T> CompletionService<T> |
newCompletionService(ExecutorService executor)
新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。
|
static CountDownLatch |
newCountDownLatch(int threadCount)
新建一个CountDownLatch
|
static ExecutorService |
newExecutor()
获得一个新的线程池
|
static ExecutorService |
newExecutor(int threadSize)
新建一个线程池
|
static ExecutorService |
newSingleExecutor()
获得一个新的线程池,只有单个线程
|
static void |
restart()
重启公共线程池
|
static boolean |
sleep(Long millis)
挂起当前线程
|
public static void execute(Runnable runnable)
runnable - 可运行对象public static void restart()
public static ExecutorService newExecutor(int threadSize)
threadSize - 同时执行的线程数大小public static ExecutorService newExecutor()
public static ExecutorService newSingleExecutor()
public static Runnable excAsync(Runnable runnable, boolean isDeamon)
runnable - 需要执行的方法体public static <T> Future<T> execAsync(Callable<T> task)
public static <T> CompletionService<T> newCompletionService()
public static <T> CompletionService<T> newCompletionService(ExecutorService executor)
public static CountDownLatch newCountDownLatch(int threadCount)
threadCount - 线程数量public static boolean sleep(Long millis)
millis - 挂起的毫秒数public static StackTraceElement[] getStackTrace()
public static StackTraceElement getStackTraceElement(int i)
i - 第几个堆栈项public static <T> ThreadLocal<T> createThreadLocal()
Copyright © 2016. All rights reserved.