When should we use Java's Thread over Executor?

后端 未结 7 1221
一个人的身影
一个人的身影 2020-11-29 23:12

Executor seems like a clean abstraction. When would you want to use Thread directly rather than rely on the more robust executor?

7条回答
  •  温柔的废话
    2020-11-29 23:30

    Well, I thought that a ThreadPoolExecutor provided better performance for it manages a pool of threads, minimizing the overhead of instantiating a new thread, allocating memory...

    And if you are going to launch thousands of threads, it gives you some queuing functionality you would have to program by yourself...

    Threads & Executors are different tools, used on different scenarios... As I see it, is like asking why should I use ArrayList when I can use HashMap? They are different...

提交回复
热议问题