Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread concepts

 
Gopinath Ranga
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
what is the diffenerce between Runnable interface and Thread class?
where do we use them?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"GopiNath R",
Welcome to JavaRanch!

We're pleased to have you here with us here on the ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Initials are OK for the first and middle names but not the last. You can change it here
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by GopiNath R:
hi all,
what is the diffenerce between Runnable interface and Thread class?


Do you understand the difference between an interface and a class?
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See you have to be specific about what you want to ask. Obvious answer to your question looks like Runnable is interface and Thread is class. If you mean to ask how are they different in terms of working, then following is your answer:

If you extend Thread then your class also becomes a thread and you cannot extend anything else. But if you implement Runnable interface, you have option to extend another Class maybe Animal or Car or whatever and also get the thread benefits by implementing Runnable.

In both the cased you just have to override run(). Call thread.Start and it will go to run method directly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic