The difference between Executors.newSingleThreadExecutor().execute(command) and new Thread(command).start();

后端 未结 6 668
醉酒成梦
醉酒成梦 2020-12-23 16:57

Well title says it, what is the difference between Executors.newSingleThreadExecutor().execute(command) and new Thread(command).start();

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 17:34

    Executors.newSingleThreadExecutor().execute(command) will reuse previously constructed thread, it will not created new thread as in case of new Thread(). If the thread that have not been used for sixty seconds are terminated, It's a kind of pool which contains a single thread which make its equivalent newFixedThreadPool(1).

提交回复
热议问题