[ajug-members] threads
Jeremy Haile
jhaile at fastmail.fm
Mon May 5 14:30:08 EDT 2008
Implementing Runnable is preferred, since it is more flexible:
1) Allows your class to extend other superclasses
2) Allows it to be reused with different implementations of the Thread
class without changing your implementation
3) Allows it to be used with schedulers, etc. such as the Java 5+
executors: http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executor.html
Also, think about it from an object oriented design class. Superclass
relationships are an "is-a" relationship. When you create a class,
ask the question "is it a Thread?" I doubt that you are actually
creating something that "is-a" thread. Instead you are creating
something that can be executed by a thread. Therefore Runnable is
more appropriate in almost all cases.
On May 2, 2008, at 9:38 PM, mcdaniel wrote:
> can anyone please answer my question?
>
> barclay
>
>>>>>
>
> 5/1/2008; barclay wrote:
>>
>> why would one ever "extend Thread" vs. "implementing Runnable"? -are
>> there speed gains/losses?
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> ajug-members mailing list
>> ajug-members at ajug.org
>> http://www.ajug.org/mailman/listinfo/ajug-members
>>
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
More information about the ajug-members
mailing list