Well title says it, what is the difference between Executors.newSingleThreadExecutor().execute(command)
and new Thread(command).start();
views:
389answers:
3
+5
A:
Behaviourally, pretty much nothing.
However, once you have an Executor
instance, you can submit multiple tasks to it, and have them executed one after another. You can't do that simply with a raw Thread
.
skaffman
2009-12-25 09:05:53
Oh yeah, that's right, didn't even think about that. Thanks.
Gnarly
2009-12-25 09:23:57
+3
A:
If an Error or RuntimeException is thrown in the Executor it will be swallowed silently, the new Thread() will print it to System.err
Peter Lawrey
2009-12-25 12:32:47
+2
A:
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.
John V.
2009-12-28 16:08:56