views:

88

answers:

2

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?

+5  A: 

Java Concurrency in Practice at least clearly states in section 6.2.:

The primary abstraction for task execution in the Java class libraries is not Thread, but Executor. [...]

Using an Executor is usually the easiest path to implementing a producer-consumer design in your application.

Péter Török
+6  A: 

Personnaly, since Java 5, i've completely left over Thread and ThreadGroup, as they provide way less customization and functionnality than ExecutorService.

When using ExecutorService, I know I can use Callable, I Know I can (with a little overhead) schedule repeted tasks. As a consequence, I consider direct instanciation of Thread objects deprecated code, as Vector and Hashtable are.

Riduidel