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

    1、 理解线程池原理;


    future可能出现的问题
    1) 取消;
    2) 异常:
    2.1) 超时异常;
    2.2) 中断异常;
    2.3) 执行异常;

    2、 数据库连接池要设置多少?

    3、 线程池要设置多少?
    io密集型一般设置为cpu数量*2
    cpu密集型一般设置为cpu+1(多线程+主线程);

    为什么加1呢?
    我想应该可能是主线程;

    corepool 50;
    blockingquene 200;
    max 500;(防止溢出;)
    keepAliveSeconds:600;线程存活时间;


    AbortPolicy:抛出异常;RejectedExecutionException;虚拟机不会关闭,程序处于阻塞状态;
    只执行blockingquene+maxpoolThreads;
    pool-1-thread-4 is running
    pool-1-thread-4 is running
    pool-1-thread-4 is running


    CallerRunsPolicy:用调用者所在线程来执行当前任务,比如说调用者在main线程,缺点:没有了多线程,没有了任何意义;
    全部执行完;
    main is running
    main is running
    main is running
    pool-1-thread-6 is running
    pool-1-thread-6 is running
    pool-1-thread-6 is running

    DiscardOldestPolicy:不抛出异常;虚拟机关闭,不处于阻塞状态;
    丢弃队列里最近的一个任务,并执行当前任务;
    只执行blockingquene+maxpoolThreads;
    pool-1-thread-3 is running
    pool-1-thread-4 is running
    pool-1-thread-4 is running


    DiscardPolicy:直接丢弃当前任务,不处理;
    只执行blockingquene+maxpoolThreads;
    pool-1-thread-5 is running
    pool-1-thread-5 is running
    pool-1-thread-6 is running

  • 相关阅读:
    Servlet设置Cookie无效
    IOS即时通讯XMPP搭建openfire服务器
    IOS之富文本编辑
    unittest单元测试框架总结
    杀死future处理的阻塞线程
    APP的UI设计原则
    如何降低一个程序的耦合性
    Hyperopt中文文档导读
    Hyperopt中文文档导读
    AdaBoost算法特性
  • 原文地址:https://www.cnblogs.com/gendway/p/10698493.html
Copyright © 2011-2022 走看看