ExecutorService vs ThreadPoolExecutor using LinkedBlockingQueue

后端 未结 6 1640
误落风尘
误落风尘 2020-12-12 20:25

I am working on a multithreaded project in which I need to spawn multiple threads to measure the end to end performance of my client code, as I\'m doing Load and Performance

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 21:22

    Here is the source of Executors.newFixedThreadPool:

     public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                                      0L, TimeUnit.MILLISECONDS,
                                      new LinkedBlockingQueue());
    }
    

    It internally uses ThreadPoolExecutor class with default configuration as you can see above. Now there are scenarios where default configuration is not suitable say instead of LinkedBlockingQueue a priority queue needs to be used etc. In such cases caller can directly work on underlying ThreadPoolExecutor by instantiating it and passing desired configuration to it.

提交回复
热议问题