File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Difference in using Runnable interface and Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Difference in using Runnable interface and Thread class" Watch "Difference in using Runnable interface and Thread class" New topic

Difference in using Runnable interface and Thread class

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello friends,

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.

Sunetra Sen
Ranch Hand

Joined: Feb 17, 2005
Posts: 43
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.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
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
I agree. Here's the link:
subject: Difference in using Runnable interface and Thread class
It's not a secret anymore!