static int getSurplusQueuedTaskCount ( ) { Thread t ; ForkJoinWorkerThread wt ; ForkJoinPool pool ; WorkQueue q ; if ( ( ( t = Thread . currentThread ( ) ) instanceof ForkJoinWorkerThread ) ) { int p = ( pool = ( wt = ( ForkJoinWorkerThread ) t ) . pool ) . config & SMASK ; int n = ( q = wt . workQueue ) . top - q . base ; int a = ( int ) ( pool . ctl >> AC_SHIFT ) + p ; return n - ( a > ( p >>>= 1 ) ? 0 : a > ( p >>>= 1 ) ? 1 : a > ( p >>>= 1 ) ? 2 : a > ( p >>>= 1 ) ? 4 : 8 ) ; } return 0 ; }
Returns a cheap heuristic guide for task partitioning when programmers frameworks tools or languages have little or no idea about task granularity . In essence by offering this method we ask users only about tradeoffs in overhead vs expected throughput and its variance rather than how finely to partition tasks .