Hello Everybody:
As we all know there are two ways to create a thread,one is by
inheriting class Thread another is by implementing interface Runnable.
An instance created by class Thread can not be reused while the one
created by interface Runnable could.Why?I think it has nothing to do
with java's single inherit or multi interface implement.If it really
does,how does this rule work then?
Any help will be greatly appreciated!
Dowson!
Knute Johnson - 04 May 2007 19:49 GMT
> Hello Everybody:
> As we all know there are two ways to create a thread,one is by
[quoted text clipped - 6 lines]
> Any help will be greatly appreciated!
> Dowson!
From the docs
public void start()
Causes this thread to begin execution; the Java Virtual Machine
calls the run method of this thread.
The result is that two threads are running concurrently: the current
thread (which returns from the call to the start method) and the other
thread (which executes its run method).
It is never legal to start a thread more than once. In particular, a
thread may not be restarted once it has completed execution.
Throws:
IllegalThreadStateException - if the thread was already started.
See Also:
run(), stop()

Signature
Knute Johnson
email s/nospam/knute/
a24900@googlemail.com - 04 May 2007 19:51 GMT
> As we all know there are two ways to create a thread,one is by
> inheriting class Thread another is by implementing interface Runnable.
Subclassing Thread: bad
Implementing Runnable and creating a separate Thread to start it: good
> An instance created by class Thread can not be reused while the one
> created by interface Runnable could.Why?
The underlying operating-system, platform-specific thread used by the
Thread object is dead after one usage and can't be resurrected.
For the rest of your question: Rework them to make sense.
Esmond Pitt - 07 May 2007 08:10 GMT
> As we all know there are two ways to create a thread,one is by
> inheriting class Thread another is by implementing interface Runnable.
There is only one way to create a Thread, and that's by calling one of
the overloads of new Thread(...). There are two ways of *providing the
Runnable code that the thread will execute*: extending Thread, or
implementing a Runnable and supplying it to the Thread's constructor.
Orthogonality concerns suggest that the latter is generally the
preferable approach.