zoukankan      html  css  js  c++  java
  • 多线程笔记


    在创建线程池的时候不管你创建的是newFixedThreadPool,还是newCachedThreadPool,还是newSingleThreadPool
    在里面调用的都是new ThreadPoolExecutor这个类,知识传入的参数值不同而已
    实例:
    public static ExecutorService newCachedThreadPool() {
    return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
    60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    }

    默认情况下,线程池中并没有任何线程,而是等待有任务到来才创建线程去执行任务

    public class ThreadPoolExecutor extends AbstractExecutorService {

        .....
        public ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,
                BlockingQueue<Runnable> workQueue);
     
        public ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,
                BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory);
     
        public ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,
                BlockingQueue<Runnable> workQueue,RejectedExecutionHandler handler);
     
        public ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,
            BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory,RejectedExecutionHandler handler);
        ...
    }
     
     
  • 相关阅读:
    Linux下shell
    分享微博@功能jquery代码及全面解析
    使用C#处理WebBrowser控件中的跨域问题
    Sqler 工具
    ASP.NET Web API批处理器
    Microsoft Academic Search
    C#中delegate对象Equals方法简析
    写一个编译器
    使用.NET中的Action及Func泛型委托
    电子政务数据库管理系统及应用软件系统安全分享(一)
  • 原文地址:https://www.cnblogs.com/handsome1013/p/9995081.html
Copyright © 2011-2022 走看看