• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread class and Runnable interface

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

When do we create a thread instance using a thread class and when do we implement the Runnable interface? Which one is preferred and why?
 
Ulf Dittmer
Rancher
Posts: 42967
73
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are the ways of creating a thread in java, but we prefer Interfaces over inheritance because it gives you flexibility to extend other class you might want.

I will extend Thread class only when my class has to be a thread only.(IS-A).

My class has to do other things beside being a thread like calculations, calling other interfaces, joining results then i will better choose Interface.Hope that will help you.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks man.. Respect..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic