问题描述
如果JDK> = 1.5,启动线程的首选方法应该始终是Executor还是Executor Service,还是仍然有理由在不需要ExecutorService提供的内容时更喜欢使用Thread.start? / p>
对于同步,我曾经认为使用新的Lock实现是首选,直到我。所以我想知道关于执行者的同样的事情。它们只是处理更复杂案例的一种方式,还是它们应该是标准选择?
就个人而言,自Java 5以来,我完全遗留了 Thread
和 ThreadGroup
,因为它们提供的定制和功能少于的ExecutorService
。
使用 ExecutorService
时,我知道我可以使用 Callable
,我知道我可以(带一点开销)安排重复的任务。因此,我考虑直接实例化 Thread
对象弃用代码,如 Vector
和 Hashtable
是。
With JDK >= 1.5, should the preferred way to start a thread always be an Executor or Executor Service, or are there still reasons to prefer to use a Thread.start if you don't need what an ExecutorService provides?
For syncronized, I used to think that using the new Lock implemenations was preferred, until I was explained otherwise. So I'm wondering the same thing about Executors. Are they just a way of handling more complex cases, or should they be the standard choice?
Personally, since Java 5, I've completely left over Thread
and ThreadGroup
, as they provide way less customization and functionality than ExecutorService
.
When using ExecutorService
, I know I can use Callable
, I know I can (with a little overhead) schedule repeated tasks. As a consequence, I consider direct instantiation of Thread
objects deprecated code, as Vector
and Hashtable
are.
这篇关于您是否应始终使用ExecutorService而不是启动自己的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!