-2

I have studied that we can create threads in two ways in java :

  1. By extending Thread Class

  2. By implementing Runnable interface under which we have to implement run()

Now my question is what is the difference b/w the two?

Is any 1 faster or efficient than other? something related to binding here or linking?

axiom
  • 8,765
  • 3
  • 36
  • 38
Akshay
  • 11
  • 3
  • Check out. http://stackoverflow.com/questions/7280881/how-many-ways-are-for-creating-a-new-thread-in-java. – axiom Apr 29 '14 at 16:33
  • -1 because a google search for "java thread runnable difference" would have given you all the answers you need – Michael Apr 29 '14 at 16:41

1 Answers1

1

A Thread is a resource for performing work.

A Runnable is a unit of work.

Are you creating a new type of resource, or defining work? It's almost always the later.

In the simplest case there isn't really any functional performance difference. However, creating Runnables allows you to utilize Thread pools without changing your code much, which is a huge boost over using new Thread() in many cases.

Affe
  • 47,174
  • 11
  • 83
  • 83