This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multithreading

 
rupika deval
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why thread class is provided when we can create a thread using runnable interface.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

There are times when you need the greater flexibility that extending Thread gives you over implementing Runnable. See ExtendingThreadVsImplementingRunnable for more information.

Since the question has nothing to do with applets -which is what this forum is about- I'll move it to the Threads and Synchronization forum.
 
P. Jain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By implementing runnable you will only get run method of that interface.

Thread class has many more methods that you can use for handling a multi threaded environment.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you can't "create a thread using runnable interface"; the magic code that actually schedules the OS-level thread to run your code in parallel is in the native methods of the Thread class.
 
Abhijit Choudhury
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know about other replies but implementing Runnable interface gives you a choice to extend any other class if you want.

You can have
class ABC extends PQR implements Runnable{
...}

You cant inherit PQR if you extend Thread Class can you?

(Multiple Inheritance NOT ALLOWED Remember)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic