Difference in using Runnable interface and Thread class
Joined: Dec 19, 2004
People say that if you just want to create thread then go for Runnable.
Here is the statement
"The Thread class has a lot more overhead (in terms of methods and attributes) and most of the time the developers only need to use the run() method.".
Now my doubt is what is this overhead ? Is it in terms of memory ? Please help me
Waiting for reply.
Joined: Feb 17, 2005
Hi, Other than the overhead stuff it is also a fact that most of the times in actual application your class(which you want to make a thread)will inherit from other classes. So as multiple extends cannot be used in java it is always advisable to implement the Runnable interface.Even if your class doesn't extend any other class presently ,you keep your option open to do that at a future date,by implementing Runnable.
The following is straight out of the API: In addition, Runnable provides the means for a class to be active while not subclassing Thread. A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. In most cases, the Runnable interface should be used if you are only planning to override the run() method and no other Thread methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.
Joined: Jul 11, 2001
Moving to Threads forum. You might want to do a search there, as this is a very frequently asked question...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus