Class GlobalThreadPool

java.lang.Object
org.miaixz.bus.core.lang.thread.GlobalThreadPool

public class GlobalThreadPool extends Object
全局公共线程池 此线程池是一个无限线程池,即加入的线程不等待任何线程,直接执行
Since:
Java 17+
Author:
Kimi Liu
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    execute(Runnable runnable)
    直接在公共线程池中执行线程
    static void
    初始化全局线程池
    static void
    shutdown(boolean isNow)
    关闭公共线程池
    static Future<?>
    submit(Runnable runnable)
    执行有返回值的异步方法 Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞
    static <T> Future<T>
    submit(Callable<T> task)
    执行有返回值的异步方法 Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • init

      public static void init()
      初始化全局线程池
    • shutdown

      public static void shutdown(boolean isNow)
      关闭公共线程池
      Parameters:
      isNow - 是否立即关闭而不等待正在执行的线程
    • getExecutor

      public static ExecutorService getExecutor()
      Returns:
      ExecutorService
    • execute

      public static void execute(Runnable runnable)
      直接在公共线程池中执行线程
      Parameters:
      runnable - 可运行对象
    • submit

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

      public static Future<?> submit(Runnable runnable)
      执行有返回值的异步方法 Future代表一个异步执行的操作,通过get()方法可以获得操作的结果,如果异步操作还没有完成,则,get()会使当前线程阻塞
      Parameters:
      runnable - 可运行对象
      Returns:
      Future