java.util.concurrent源码学习系列--Executor

Executor的系列类图如下:这一些了类或接口都是和任务提交和执行相关的。

 

  • java.util.concurrent.AbstractExecutorService (implements java.util.concurrent.ExecutorService extends  java.util.concurrent.Executor)
    • java.util.concurrent.ThreadPoolExecutor
      • java.util.concurrent.ScheduledThreadPoolExecutor (implements java.util.concurrent.ScheduledExecutorService extends  java.util.concurrent.ExecutorService)
  • java.util.concurrent.Executors

java.util.concurrent.Executor接口:

Java代码   收藏代码
  1.  /* @since 1.5 
  2.  * @author Doug Lea 
  3.  */  
  4. public interface Executor {  
  5.   
  6.     /** 
  7.      * Executes the given command at some time in the future.  The command 
  8.      * may execute in a new thread, in a pooled thread, or in the calling 
  9.      * thread, at the discretion of the Executor implementation. 
  10.      *会在将来某个时刻去执行任务,也就是所谓的异步执行 
  11.      * 
  12.      * @param command the runnable task 
  13.      * @throws RejectedExecutionException if this task cannot be 
  14.      * accepted for execution. 
  15.      * @throws NullPointerException if command is null 
  16.      */  
  17.     void execute(Runnable command);  
  18. }  

java.util.concurrent.ExecutorService接口,该接口定义的方法如下:


java.util.concurrent源码学习系列--Executor_第1张图片
 这些方法一部分在AbstractExecutorService提供了默认的实现,一部分延迟到ThreadPoolExecutor里实现。

java.util.concurrent.AbstractExecutorService抽象类:
参考: AbstractExecutorService.submit
参考: AbstractExecutorService .invokeAll
参考: AbstractExecutorService.invokeAny

java.util.concurrent.ThreadPoolExecutor类:
参考: ThreadPoolExecutor.execute

你可能感兴趣的:(后端技术)