b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

forkjoinpool_forkjoinpool 线程数_forkjoinpool 原理(2)

电脑杂谈  发布时间:2017-04-10 15:01:06  来源:网络整理

继续看被调用的constructor。forkjoinpool在这个里面已经初始化了好多ForkJoinPool的字段了。

if (factory == null)
            throw new NullPointerException();
        if (parallelism <= 0 || parallelism > MAX_ID)
            throw new IllegalArgumentException();
        this.parallelism = parallelism;
        this.factory = factory;
        this.ueh = handler;
        this.locallyFifo = asyncMode;
        long np = (long)(-parallelism); // offset ctl counts
        this.ctl = ((np << AC_SHIFT) & AC_MASK) | ((np << TC_SHIFT) & TC_MASK);
        this.submissionQueue = new ForkJoinTask<?>[INITIAL_QUEUE_CAPACITY];
        // initialize workers array with room for 2*parallelism if possible
        int n = parallelism << 1;
        if (n >= MAX_ID)
            n = MAX_ID;
        else { // See Hackers Delight, sec 3.2, where n < (1 << 16)
            n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8;
        }
        workers = new ForkJoinWorkerThread[n + 1];
        this.submissionLock = new ReentrantLock();
        this.termination = submissionLock.newCondition();
        StringBuilder sb = new StringBuilder("ForkJoinPool-");
        sb.append(poolNumberGenerator.incrementAndGet());
        sb.append("-worker-");
        this.workerNamePrefix = sb.toString();

挨个看看字段的解释吧:

/**
 * The target parallelism level.
 * 并行化级别,就是说可以有多少个线程程池中同时工作.
 */
 final int parallelism;
/**
 * Creation factory for worker threads.
 * 线程池的工厂,刚才上面分析过了...
 */
 private final ForkJoinWorkerThreadFactory factory;
/**
 * The uncaught exception handler used when any worker abruptly
 * terminates.
 * 经过刚刚的初始化后,这个参数是null
 */
 final Thread.UncaughtExceptionHandler ueh;
 /**
  * True if use local fifo, not default lifo, for local polling
  * Read by, and replicated by ForkJoinWorkerThreads
  * 还没搞明白目前...但是可以确定的是这个参数初始化以后是false
  */
  final boolean locallyFifo;
// 这个参数太复杂...专题分析以后...
volatile long ctl;

 /**
  * Array serving as submission queue. Initialized upon construction.
  * 提交任务的队列..
  */
  private ForkJoinTask<?>[] submissionQueue;
 /**
 * Arry holding all work threads in the pool
 * 其实就是线程池....
 **/
 ForkJoinWorkerThread[] workers;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-40528-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 杜海广
      杜海广

      一是少数民族封建统治

    热点图片
    拼命载入中...