The value of the thread pool (iii) the value of the boundary blocking queue thread pool values (two) important design throughput

In the last, the thread pool values (b) the design throughput is important , use unbounded LinkedBlockingQueue receive queue, we will take a look at the blocking queue changed to 36:

 

import java.util.concurrent.*;

/**
 * https://www.cnblogs.com/silyvin/p/11806859.html
 * https://www.cnblogs.com/silyvin/p/11875907.html
 * Created by joyce on 2019/11/6.
 */
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.SECONDS)
@Threads(40)
@State(Scope.Thread)
public class MyThread {

    private static final ThreadPoolExecutor MQ_POOL = new ThreadPoolExecutor(
            4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(36),
            new DefaultThreadFactory("mq-", true));
    
    public static class action implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            int a = 0;
            Thread.sleep(2000);
            System.out.println(a);
            return a;
        }
    }

    @Benchmark
    public static void testS() {
        try {
            Future<Integer> i = MQ_POOL.submit(new action());
            i.get();
        } catch (RejectedExecutionException e) {
            System.out.println("放弃" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String [] f) throws RunnerException {
        
        // jhm压力测试
        Options opt = new OptionsBuilder().include(MyThread.class.getSimpleName()).forks(1).warmupIterations(0)
                .measurementIterations (. 1) .build (); 

        new new Runner (opt) .run (); 

        // own stress test 
        MyYali.start (40); 


    } 

    Private static class MyYali the implements the Runnable { 

        public static void Start (int threadCount) { 

            for (int I = 0; I <threadCount; I ++) { 
                new new the Thread (new new MyYali ()) Start ();. 
            } 
        } 

        // if this place is not an error 
        Private int COUNT = 2; 

        @Override 
        public RUN void () { 
            for(int i=0; i<count; ++i) {
                TESTS (); 
            } 
        } 
    } 
}

 

2 jhm own cycles measured pressure

A plurality of blocking queue length 36 to give up, give up to 19 1, in each occurrence, fairly stably 4th Printing "0" Response Time 28

Blocking queue length of 37 is not abandoned, 20 did not give a response time

 

Cycles 1        

Blocking queue length 36 / did not give 

Blocking queue length 37 / did not give

  

 

放弃Task java.util.concurrent.FutureTask@1339fcef rejected from java.util.concurrent.ThreadPoolExecutor@300fa78c[Running, pool size = 4, active threads = 4, queued tasks = 35, completed tasks = 14]

 

According to all the speculation phenomenon, combined with handwriting blocking queue reduction, why 36 out of the threads is rejected

 

Guess you like

Origin www.cnblogs.com/silyvin/p/11875907.html