SingleThreadExecutor VS plain thread

前端 未结 4 1296
情话喂你
情话喂你 2021-02-11 19:39

Apart from the fact that the Executor interface has some advantages over plain threads (management, for example), is there any real internal difference (big perform

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-11 19:58

    If you only get one Runnable to execute, then there is no big difference between them.

    Using plain thread may be a little more efficient because creating an ExecutorService such as ThreadPoolExecutor has something to do besides creating a new thread. For example, creating blocking queue, creating policy, though these things are done implicitly.

    And you have to shutdown the executor after this runnable has been executed. Otherwise the single thread in this pool will never exit.

提交回复
热议问题