UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

I want to know what are the differences between runnable and thread class implementation except they are class and interface and how to decide which is better at what time ...

Asked by Last Modified  

21 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go. 2) Java only supports single inheritance, so you can only extend one class. 3)...
read more
1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go. 2) Java only supports single inheritance, so you can only extend one class. 3) Instantiating an interface gives a cleaner separation between your code and the implementation of threads. 4) Implementing Runnable makes your class more flexible. If you extend thread then the action you’re doing is always going to be in a thread. However, if you extend Runnable it doesn’t have to be. You can run it in a thread, or pass it to some kind of executor service, or just pass it around as a task within a single threaded application. 5) By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance. read less
Comments

Industry expert and professional lecturer/trainer

Well it depends on your need. Generally you extend any class when either you want to over ride or use all or most of the methods and interface you want to implement the methods. In Thread class there are tons of methods but we override only one run() method and Runnable interface has only one method...
read more
Well it depends on your need. Generally you extend any class when either you want to over ride or use all or most of the methods and interface you want to implement the methods. In Thread class there are tons of methods but we override only one run() method and Runnable interface has only one method to implement that is run(). So its a performance benefit and common sens to use Runnable interface than Thread class. read less
Comments

IT Professional Trainer working with a reputed Institute. Headquarters: Hyderabad

Thread vs. Runnable in Java 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means...
read more
Thread vs. Runnable in Java 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means adding new functionality, modifying or improving behaviors. If we are not making any modification on Thread than use Runnable interface instead. 3) Runnable interface represent a Task which can be executed by either plain Thread or Executors or any other means. So logical separation of Task as Runnable than Thread is good design decision. 4) Separating task as Runnable means we can reuse the task and also has liberty to execute it from different means. Since you cannot restart a Thread once it completes. Again Runnable vs Thread for task, Runnable are winner. 5) Java designer recognizes this and that's why Executors accept Runnable as Task and they have worker thread which executes those task. read less
Comments

Java,J2EE,Spring,Webservices,Hibernate,Cloud And Android Expertise

Runnable is better if your class still wanted to extend or implement any other class. If your class is responsible only for thread activities and if you dont want to extend any other class then use Thread.
Comments

Here are some of my thoughts on whether I should use Thread or Runnable for implementing task in Java, though you have another choice as "Callable" for implementing thread which we will discuss later. 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so...
read more
Here are some of my thoughts on whether I should use Thread or Runnable for implementing task in Java, though you have another choice as "Callable" for implementing thread which we will discuss later. 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means adding new functionality, modifying or improving behaviors. If we are not making any modification on Thread than use Runnable interface instead. 3) Runnable interface represent a Task which can be executed by either plain Thread or Executors or any other means. so logical separation of Task as Runnable than Thread is good design decision. 4) Separating task as Runnable means we can reuse the task and also has liberty to execute it from different means. since you can not restart a Thread once it completes. again Runnable vs Thread for task, Runnable is winner. 5) Java designer recognizes this and that's why Executors accept Runnable as Task and they have worker thread which executes those task. 6) Inheriting all Thread methods are additional overhead just for representing a Task which can can be done easily with Runnable. These were some of notable difference between Thread and Runnable in Java, if you know any other differences on Thread vs Runnable than please share it via comments. I personally use Runnable over Thread for this scenario and recommends to use Runnable or Callable interface based on your requirement. read less
Comments

Trainer

If you dont have any parent class go for Thread . If you have any parent class then go for Runnable . Both are the same.
Comments

If we want to make a sub class as thread class, we must use Runnable interface instead of Thread class, because already the sub class is extends from another super class, hence it cannot extends another class (Thread). Multiple inheritance is not supported in java
Comments

explore the depth of 'C' language..

The difference is that when u r implementing an interface u will have to provide the bodies for all the functions inside the class in which u r implementing.
Comments

Java Trainer

Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance andcan not extend or inherit another class in Java. But by implementing Runnable Interface we can get a chance to extends one more class. By...
read more
Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance andcan not extend or inherit another class in Java. But by implementing Runnable Interface we can get a chance to extends one more class. By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance. read less
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Thread vs Runnable in Java is always been a confusing decision for beginners in java. Thread in Java seems easy in comparison of Runnable because you just deal with one class java.lang. Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes....
read more
Thread vs Runnable in Java is always been a confusing decision for beginners in java. Thread in Java seems easy in comparison of Runnable because you just deal with one class java.lang. Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes. Though decision of using Runnable or Thread should be taken considering differences between Runnable and Thread and pros and cons of both approaches. This is also a very popular thread interview questions and most of interviewer are really interested to know what is your point of view while choosing Thread vs Runnable or opposite. In this java article we will try to point out some differences between Thread and Runnable in Java which will help you to take an informed decision. read less
Comments

View 19 more Answers

Related Questions

Hi every one i have done my I com so plzz suggest me it course. I want do carrer in it field

First of all you should take the degree course with full concept because when you have chosen this subject then you will haveto try for best performance in it
Aquib
0 0
9
Why using Overriding in Java ?
There was a student who always pronounces "University" as "Univerkity". His teacher got angry and called the parents and asked to know the reason. Teacher got shocked as they are pronouncing "Capacity"...
Shivendra
What is a good foundation course for JAVA?
I will not prefer any programming language or technology instead, You can focus on Concept and Principles. Because when you say your a programmer you should be a programmer rather than saying Java programmer,...
Rajeev J
Why Java doesnot have Pointer ?
To avoid memory hacks and leaks it is an intentional decision taken by JAva Pioneers
Satyajit
What is difference between throw and throws in Java programming?
throw keyword is used to throw Exception from any method or static block in Java while throws keyword, used in method declaration, denoted which Exception can possible be thrown by this method
Vinodha

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Introduction to Course Content
Video about what we are going to learn throughout the Java Training Session .

Overloading in JAVA
When a class contains more than one method with the same method name but different argument types, then it is called Overloading. Methods are said to be Overloaded methods. Also, know as Compile time...

TestNG Annotations and its sequence
public class TestNGAnnotations { @BeforeMethod public void beforeM() { System.out.println("Before Method"); } @AfterMethod public void afterMethod() { System.out.println("After Method"); } @BeforeClass...
S

Sarthak C.

0 0
0

jOOQ 3.10 Supports JPA Attribute Converter
One of the cooler hidden features in jOOQ is the JPADatabase, which allows for reverse engineering a pre-existing set of JPA-annotated entities to generate jOOQ code. For instance, you could write these...

Java Advantages
In this video, learn about Java and its advantages. Also, check out the difference between Java and C++, Java development kit, Java Run Time Environment (JRE) with a proper demonstration program for better clarity.

Recommended Articles

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more