zoukankan      html  css  js  c++  java
  • 线程池体系

    线程池类图

    |-Java.util.concurrent.Executor 负责线程的使用与调度的根接口

    |-ExecutorService:Executor的子接口,线程池的主要接口

    |-AbstractExecutorService:实现了ExecutorService接口,基本实现了ExecutorService其中声明的所有方法,另有添加其他方法

    |-ThreadPoolExecutor:继承了AbstractExecutorService,主要的常用实现类

    |-ScheduledExecutorService:继承了ExecutorService,负责线程调度的接口

    |-ScheduledThreadPoolExecutor:继承了ThreadPoolExecutor同时实现了ScheduledExecutorService

    Executor接口

    public interface Executor {
        void execute(Runnable command);
    }

    ExecutorService接口

    public interface ExecutorService extends Executor {
        void shutdown();
        List<Runnable> shutdownNow();
        boolean isShutdown();
        boolean isTerminated();
        boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;
        Future<?> submit(Runnable task);    //实现无返回值的Runnable接口
        <T> Future<T> submit(Callable<T> task);   //实现有返回值的Callable接口
        <T> Future<T> submit(Runnable task, T result);  //实现无返回值的Runnable接口并自定义返回值
        <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)throws InterruptedException;   
        <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,long timeout, TimeUnit unit)throws InterruptedException;    
        <T> T invokeAny(Collection<? extends Callable<T>> tasks)throws InterruptedException, ExecutionException;    
        <T> T invokeAny(Collection<? extends Callable<T>> tasks,long timeout, TimeUnit unit)throws InterruptedException, ExecutionException, TimeoutException;
    }

    ScheduledExecutorService接口

    package java.util.concurrent;
    public interface ScheduledExecutorService extends ExecutorService {
        public ScheduledFuture<?> schedule(Runnable command,long delay, TimeUnit unit);
        public <V> ScheduledFuture<V> schedule(Callable<V> callable,long delay, TimeUnit unit);
        //以固定频率来执行线程任务,固定频率的含义就是可能设定的固定时间不足以完成线程任务,但是它不管,达到设定的延迟时间了就要执行下一次了
        public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit);
        //以固定延迟(时间)来执行线程任务,它实际上是不管线程任务的执行时间的,每次都要把任务执行完成后再延迟固定时间后再执行下一次
        public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,long initialDelay,long delay,TimeUnit unit);
    }
  • 相关阅读:
    分布式文件系统 FastDFS
    Autoit里用多进程模拟多线程
    请不要做浮躁的人(新手必读!)
    如何用AU3调用自己用VC++写的dll函数
    DLL编写教程
    win32下的命令行集合 (最优秀的工具)
    autoit 《FAQ 大全》
    Windows XP 常用DOS命令
    rundll32 常用命令
    批处理的高级运用技巧
  • 原文地址:https://www.cnblogs.com/walixiansheng/p/9588389.html
Copyright © 2011-2022 走看看