Testing PriorityBlockingQueue in ThreadPoolExecutor

前端 未结 2 596
半阙折子戏
半阙折子戏 2020-12-17 03:03

I realized my ThreadPoolExecutor with PriorityBlockingQueue like in this example: https://stackoverflow.com/a/12722648/2206775

and wrote a test:

Prio         


        
2条回答
  •  隐瞒了意图╮
    2020-12-17 03:45

    You have 16 threads and only 5 tasks, meaning all of them are being executed concurrently and the priority is actually irrelevant.

    The priority only matters when there are tasks waiting to be executed.

    To show this, if you set your example to only use 1 thread, you will get your expected output.

提交回复
热议问题