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

后端 未结 6 552
醉酒成梦
醉酒成梦 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:30

    One noticeable difference, is when you run new Thread(someRunnable).start(); when the runnable is finished the thread will die quietly.

    The Executor though will persist until you shut it down. So running Executors.newSingleThreadExecutor().execute(command) When you think your application or the JVM may be finished the Executor may still be running in a background thread.

提交回复
热议问题