When should we use Java's Thread over Executor?

后端 未结 7 1229
一个人的身影
一个人的身影 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:20

    java.util.concurrent package provides executor interface and can be used to created thread.

    The Executor interface provides a single method, execute, designed to be a drop-in replacement for a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace

    (new Thread(r)).start();

    with

    e.execute(r);

    Refer here

提交回复
热议问题