com.xiaoleilu.hutool
类 ThreadUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.ThreadUtil

public class ThreadUtil
extends Object

线程池工具

作者:
luxiaolei

构造方法摘要
ThreadUtil()
           
 
方法摘要
static Runnable excAsync(Runnable runnable, boolean isDeamon)
          执行异步方法
static
<T> Future<T>
execAsync(Callable<T> task)
          执行有返回值的异步方法
Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞
static void execute(Runnable runnable)
          直接在公共线程池中执行线程
static
<T> CompletionService<T>
newCompletionService()
          新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。
static
<T> CompletionService<T>
newCompletionService(ExecutorService executor)
          新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。
static CountDownLatch newCountDownLatch(int threadCount)
           
static ExecutorService newExecutor()
          获得一个新的线程池
static ExecutorService newExecutor(int threadSize)
          新建一个线程池
static void restart()
          重启公共线程池
static boolean sleep(Long millis)
          挂起当前线程
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

ThreadUtil

public ThreadUtil()
方法详细信息

execute

public static void execute(Runnable runnable)
直接在公共线程池中执行线程

参数:
runnable - 可运行对象

restart

public static void restart()
重启公共线程池


newExecutor

public static ExecutorService newExecutor(int threadSize)
新建一个线程池

参数:
threadSize - 同时执行的线程数大小
返回:
ExecutorService

newExecutor

public static ExecutorService newExecutor()
获得一个新的线程池

返回:
ExecutorService

excAsync

public static Runnable excAsync(Runnable runnable,
                                boolean isDeamon)
执行异步方法

参数:
runnable - 需要执行的方法体
返回:
执行的方法体

execAsync

public static <T> Future<T> execAsync(Callable<T> task)
执行有返回值的异步方法
Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞

返回:
Future

newCompletionService

public static <T> CompletionService<T> newCompletionService()
新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。,若未完成,则会阻塞

返回:
CompletionService

newCompletionService

public static <T> CompletionService<T> newCompletionService(ExecutorService executor)
新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。,若未完成,则会阻塞

返回:
CompletionService

newCountDownLatch

public static CountDownLatch newCountDownLatch(int threadCount)

sleep

public static boolean sleep(Long millis)
挂起当前线程

参数:
millis - 挂起的毫秒数
返回:
被中断返回false,否则true


Copyright © 2014. All rights reserved.