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

Thread vs Runnable better OO

ZahidM Khan

Joined: Apr 06, 2012
Posts: 8
You can define and instantiate a thread in one of two ways:
■ Extend the java.lang.Thread class.
■ Implement the Runnable interface.

In both cases we have to override run() method.

How come when we extend class we combine both the thread and the job (the code in the run()method) into one class, and when we implement Runnable we've split it into two classes—the Thread class for the thread-specific code and your Runnable implementation class for your job-that-should-be-run-by-a-thread code.?
Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

The Thread class should never have been declared to implement Runnable. It is a design flaw that we can extend Thread instead of implementing Runnable. Thread's job is to execute a task in its own thread of execution. Runnable's job is to be that task.
I agree. Here's the link:
subject: Thread vs Runnable better OO
It's not a secret anymore!