Diff between Runnable Interface and Thread class while using threads

Diff between Runnable Interface and Thread class while using threads

Diff between Runnable Interface and Thread class while using threads

View Answers

January 10, 2011 at 3:35 PM

Hi Friend,

Difference:

1)If you want to extend the Thread class then it will make your class unable to extend other classes as java is having single inheritance feature whereas If you implement runnable interface, you can gain better object-oriented design and consistency and also avoid the single inheritance problems.

2)Extending the thread will give you simple code structure in comparison to Runnable Interface.

3)Using Runnable Interface, you can run class several times whereas Thread have the start() method that can be called only once.

Thanks

Ads









Related Tutorials/Questions & Answers:
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads  Diff between Runnable Interface and Thread class while using threads  ... to Runnable Interface. 3)Using Runnable Interface, you can run class several
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads  Diff between Runnable Interface and Thread class while using threads  ... to Runnable Interface. 3)Using Runnable Interface, you can run class several
Advertisements
Creation of Multiple Threads
than one thread (multithreads) in a program using class Thread or implementing... create the same program implenting the Runnable interface: class MyThread1... Thread or interface Runnable to implement thread in your program. Download
Runnable interface in java
In this section we will learn about Runnable interface in java. In java thread are created by two ways, one by extending Thread class and another one by implementing Runnable interface
Java : Runnable Thread
by using Runnable interface. class RunnableThread implements Runnable... a thread by implementing the Runnable interface. You need to implement a single.... After creating class that implements Runnable interface, you can create object
Difference between abstract class and an interface
Difference between abstract class and an interface The difference between abstract class and interface is one of the most popular question in the interview... between abstract class and interface in java. Abstract class is a class
Creation of MultiThreads
class Thread or interface Runnable to implement thread in your program... create more than one thread (multithreads) in a program using class Thread..., lets create the same program implenting the Runnable interface: class
Count Active Thread in JAVA
of active threads in the current thread group. Example : class ThreadCount...Count Active Thread in JAVA In this tutorial, we are using activeCount() method of thread to count the current active threads. Thread activeCount
Diff between ArrayList and Vector?
Diff between ArrayList and Vector?  What's The Difference between ArrayList and Vector Classes and Can you give me a simple Program for set and List Interface
Creation of MultiThreads
thread (multithreads) in a program using class Thread or implementing interface.... It means, you can use either class Thread or interface Runnable to implement thread... by extending Thread Class:  class MyThread extends 
diff between encapsulation and abstraction code
diff between encapsulation and abstraction code  diff between encapsulation and abstraction code
Creating multiple Threads
they are as follows: By implementing Runnable interface. By extending Thread class. While implementing Runnable interface or extending Thread class, you have... class B extends Thread { public void run() { System.out.println(); for (int i
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
Email queue while sending mail using Struts Class
Email queue while sending mail using Struts Class  Can I maintain a queue of mails being sent from a JSP page in a DB to get its status
Threads
Threads  Extends Thread or Implementing Runnable Interface... flexibility for the Runnable implementation to extend another class. 2)Separates the code from execution 3)Allows you to run your runnable from a Thread Pool
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
How to remove the space between a JComponent and its Grid border while using GridBagLayout?
How to remove the space between a JComponent and its Grid border while using GridBagLayout?   Hi, I had try to design a UI using GridBagLayout.I... space between the Label text and the TextBox.Could anyone help me to reduce
Interface and Abstract class
Interface and Abstract class  Difference between Interface and Abstract class? Give some example   Difference Between Interface... interface should be implemented using keyword 'implements'; A Java abstract class should
Thread
the Thread class and the second is to implement the Runnable interface. Please... methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output
diff between encapsulation and abstraction code with output   diff between encapsulation and abstraction code with output
Java Thread : isAlive() method
threads ,java take long periods switching between threads , may be one of your thread dead. This can be checked by using method Thread.isAlive(). boolean.... Example :  In this example we are checking thread is alive or not. class
Java :Thread Methods
(). Example : class RunnableThread implements Runnable { Thread thread...Java :Thread Methods This section explains methods of Thread class. Thread Methods : Thread class provides many method to handle different thread
Java Exception Thread
Thread There are method to create thread 1)Extends the Threads Class( java.lang.thread) 2)Implement Runnable interface( java .lang. thread) Understand Exception in Threads. 1.A class name RunnableThread  implements the Runnable
Abstract class and interface in Java
Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between an interface and an abstract class: At the same time multiple interfaces can
Thread Priorities
the execution schedule of threads . Thread gets the ready-to-run state according... to be executed, the runtime system chooses the runnable thread with the highest priority... threads are runnable then the runtime system chooses the new higher priority
implementing an algorithm using multi threads - Java Beginners
ends"); } } class A implements Runnable { File f; FileOutputStream fos... thread B"); for(int i=0;i<250000;i++) { /*while(available==true...(); } } } class C implements Runnable { double a; double b; double lamsq
Threads
Threads   class Extender extends Thread { Extender(Runnable...(); } } class Implementer implements Runnable { public void run...();} public void run(){ System.out.println("Extender Thread
difference between main thread and child thread?
difference between main thread and child thread?  any one give correct exact difference.   in jsp 7 implicit objects are available those are 1:response->This denotes the data included with the HTTP Response. 2
interfaces,exceptions,threads
class. In java, multiple inheritance is achieved by using the interface... THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface... or non static variables.Any class can implement(inherit)the interface and make use
pls tell me the difference between the run() and start() in threads in java....
pls tell me the difference between the run() and start() in threads in java....  difference between the run() and start() in threads in java
Thread Life Cycle Example in java
stages of Thread in Java. These states are New State, Runnable State, Running... of Thread class or you can create a subclass of Thread and then you can create an instance of your class. Example : Thread thread = new Thread(); Newly
Threads
Threads   class Extender extends Thread { Extender(Runnable run...; }<br> } class Implementer implements Runnable { public void run...(); } public void run(){<br> System.out.println("Extender Thread
Thread Priorities
the execution schedule of threads . Thread gets the ready-to-run state according... to be executed, the runtime system chooses the runnable thread with the highest... threads are runnable then the runtime system chooses the new higher priority
Threads in Java
and it cannot run again While the thread is in Running state, it can further enter into non-runnable states: Sleeping: A thread here sleeps for a specified... and allows other threads to execute. Example of Threads in Java: public class
Threads(suspend(),resume()) run time abnormal behaviour
Threads(suspend(),resume()) run time abnormal behaviour   class A implements Runnable { Thread t; A() { t... A thread and main thread both stop working and the program hangs in between
Java :Thread getPriority Example
the priority of your thread. Example : class ThreadGetPriority implements Runnable...Java :Thread getPriority Example In this tutorial you will learn how to get thread priority in java thread. Thread getPriority() : Thread scheduler uses
Thread
.   Java Thread Example class ThreadExample{ static int...) { } } }; Thread thread1 = new Thread(readRun1); thread1.start(); Runnable...Thread  Write a Java program to create three theads. Each thread
Interface vs abstract class
Interface vs abstract class  Hai, Is there any possible to defining abstract methods in Interface
Thread Priorities
schedule of threads . Thread gets the ready-to-run state according..., the runtime system chooses the runnable thread with the highest priority.... If at the execution time a thread with a higher priority and all other threads
difference between enum and final class?
difference between enum and final class?  what is the difference between enum and final class in java?   The java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types
Java Thread
threads for concurrent execution. Each thread has priority. You can also set priority to threads. Thread having higher priority will execute first... the thread. Runnable : when you call start() it enter into the runnable
Why the wait(),notify() should not avaialable in Thread class.
Why the wait(),notify() should not avaialable in Thread class.  wait(),notify(),notifyall() is available in Object class.We are using those method in Threading then why don't they put the 3 methods in thread class
What Is Thread In Java?
by extending a Thread class or by implementing a Runnable interface. Here we will give... the interface. Thread Example using extending Thread class MyThread.java class..."); } } Thread Example using implementing Runnable interface
exception in thread main while running servlet
exception in thread main while running servlet  I got exception in thread main no such method error while running servlet. I have added servlet.api.jar file in classpath.my classpath is C:\Program Files\Apache Software Foundation
creating trafficsignal using thread
creating trafficsignal using thread  please give me code how to create trafic signal using thread and give me it to my email [email protected] thanks
Thread Creation
the Runnable Interface is as follows: A Class implements the Runnable... of Thread Class by passing a Runnable object as argument. Invoke the start( ) method... the thread creation implenting the Runnable interface: class 
Java Interview Questions - Page 5
;extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method... is started, via its start() method of the Thread class, the JVM invokes
java code using while loop
java code using while loop  

Ads