Home Answers Viewqa Java-Interview-Questions Java Thread and Runnable

 
 


samar
Java Thread and Runnable
1 Answer(s)      2 years and 7 months ago
Posted in : Java Interview Questions

What's the difference between Thread and Runnable types?
View Answers

October 27, 2010 at 6:12 PM


Hi,

Here is the answer,

A Java Thread controls the main path of execution in an application. When you invoke the Java Virtual Machine with the java command, it creates an implicit thread in which to execute the main() method. The Thread class provides a mechanism for the first thread to start-up other threads to run in parallel with it.

The Runnable interface defines a type of class that can be run by a thread. The only method it requires is run(), which makes the interface very easy to fulfil by extending existing classes. A runnable class may have custom constructors and any number of other methods for configuration and manipulation.

Thanks.









Related Pages:
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
Java : Runnable Thread
Java : Runnable Thread In this tutorial we are describing Runnable Thread with example. Runnable Thread : Runnable thread is an easy way to create a thread by implementing the Runnable interface. You need to implement a single
implements runnable n extends thread - Java Beginners
implements runnable n extends thread  what is the difference between implements runnable n extends thread? public class...(); class StringThreadImplement implements Runnable { private String } }  Hi public class
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main... is to implement the Runnable interface. Please Visit Here   Java
Thread
. At this point, the thread is considered not alive. Runnable (Ready-to-run) state ? A thread start its life from Runnable state. A thread first enters runnable state... in Running state: the scheduler select a thread from runnable pool. Dead state
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
Thread
Thread  Write a Java program to create three theads. Each thread....   Java Thread Example class ThreadExample{ static int...) { } } }; Thread thread1 = new Thread(readRun1); thread1.start(); Runnable
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   Hi Friend, Difference: 1)If you want to extend the Thread class
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   Hi Friend, Difference: 1)If you want to extend the Thread class
Java Runnable Interface
Java Runnable Thread is a piece of the program execution. Java Runnable is an interface. Thread class implements it. Java has multithreading facility. Thread is also created by implementing the Runnable interface. Java
Threads on runnable interface - Java Beginners
://www.roseindia.net/java/thread/thread-creation.shtml...Threads on runnable interface  need a program.....please reply asap Create 2 threads using runnable interface.First threads shd print "hello
Threads on runnable interface - Java Beginners
Threads on runnable interface  need a program.....please reply asap Create 2 threads using runnable interface.First threads shd print "hello....  Hi manshi, i am sending simple code of thread. class MyThread
Difference between extends thread class vs implements runnable interface - Java Interview Questions
Difference between extends thread class vs implements runnable interface  Hi Friends, can you give difference between extending thread class... Runnable Interface, you can run the class several times whereas Thread have
runnable - Java Beginners
runnable  is java.lang.Runnable is marker interface?  Hi Friend, We all know that marker interface does not contain any method. But Runnable is a marker interface even though it is having run() method. Thanks
Thread scheduling
?  Java uses fixed-priority scheduling algorithms to decide which thread... on the basis of their priority relative to other Runnable threads. The thread... is started, Java makes the lower priority thread wait if more than one thread exists
Thread
Thread  class Extender extends Thread { Extender(Runnable run...(); } public void run(){ System.out.println("Extender Thread is Started :"); //new Thread(new Implementer()).start(); } } class Implementer
Main Thread and Child Thread
when program runs. Child Thread gets created by the main thread . Java Main Thread Example public class mainchild implements Runnable { Thread t1... There are two types of threads in Java Progarm In Java there are Main
Java Thread
Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple... the thread. Runnable : when you call start() it enter into the runnable
To make java exe or runnable file
To make java exe or runnable file   Helo sir i make a java application.I need to help how run application direct in pc i.e how it packaged, .exe file or setup file
JAVA THREAD - Java Beginners
JAVA THREAD  hii i wrote a pgm to print the numbers from 0 to 9 in 2...: class kj implements Runnable { public static void main(String ar[])throws...); } public void fgh(int i,int p) { int sum; new Thread(public void run
Java :Thread getPriority Example
Java :Thread getPriority Example In this tutorial you will learn how to get thread priority in java thread. Thread getPriority() : Thread scheduler uses... the priority of your thread. Example : class ThreadGetPriority implements Runnable
Java Thread : getState() Example
Java Thread : getState() Example This section explains how to get state of a thread  in java Thread. Thread  getState() : Suppose you want to know the state of the thread so for that Java Thread provides Thread.getState
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism...:/www.roseindia.net/java/thread/index.shtml
Java :Thread setPriority Example
Java :Thread setPriority Example In this tutorial you will learn how to set thread priority in java thread. Thread setPriority() : Thread scheduler uses... to the current thread. class ThreadSetPriority implements Runnable { Thread
Thread
Thread  Explain the use of throw and throws keywords.   Java throw and throws Whenever we want to force an exception then we use throw... a possible exception then we use throws keyword. Point to note here is that the Java
java thread - Java Beginners
java thread  PROJECT WORK: Create a application using thread... demonstrates the use of Runnable interface to transfer money from one account... . AccountManager.java The AccountManager class demonstrates creation of Thread objects using
Thread Priorities
;   In Java, thread scheduler can use the thread priorities... a Java thread is created, it inherits its priority from the thread..., the runtime system chooses the runnable thread with the highest priority
Thread Priorities
;    In Java, thread scheduler can use the thread...; When a Java thread is created, it inherits its priority from the thread... to be executed, the runtime system chooses the runnable thread with the highest priority
Java Thread class
It is created by extending the Thread class or implementing Runnable interface Java Thread Class Example public class thread1 extends Thread { @Override... Java Thread Class is a piece of the program execution Java has
Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking... is possible. In other words, a situation where a thread is waiting for an object lock that holds by second thread, and this second thread is waiting for an object
Thread - Java Beginners
Thread  Can i ask a thread method that will input two names using...(true); final Runnable doHelloWorld = new Runnable() { public void run...()); } }; Thread appThread = new Thread() { public void run() { try
Java :Thread Methods
Java :Thread Methods This section explains methods of Thread class. Thread Methods : Thread class provides many method to handle different thread...(). Example : class RunnableThread implements Runnable { Thread thread
Thread Priorities
;    In Java, thread scheduler can use the thread...; When a Java thread is created, it inherits its priority from the thread... to be executed, the runtime system chooses the runnable thread with the highest
Java Thread : toString() method
Java Thread : toString() method In this section we are going to describe toString() method with example in java thread. toString() method : If you want... to display info of thread. public class ThreadToString implements Runnable
Java Thread : setDaemon() method
Java Thread : setDaemon() method In this section we are going to describe setDaemon() method with example in java thread. Daemon Thread  : In Java... Runnable { public void run() { System.out.println("Thread name
Thread Creation
; In Java, an object of the Thread class can represent a thread. Thread... RunThread.java C:\j2se6\thread>java RunThread Thread... of Thread Class by passing a Runnable object as argument. Invoke the start( ) method
Java Thread : run() method
Java Thread : run() method In this section we are going to describe run() method with example in java thread. Thread run() : All the execution code...() method. public class ThreadRun implements Runnable { Thread thread
Java Thread : isAlive() method
Java Thread : isAlive() method In this tutorial you will learn how to use isAlive() method in java thread. isAlive() method : When you are running many... ThreadIsAlive implements Runnable { @Override public void run() { Thread
Java Thread setName
Java Thread setName() method sets the new name to each Thread. It is used in both Thread class and Runnable interface. Name is also set by the string data used in the constructor. Java Thread setName Example public class
Java Exception Thread
( java.lang.thread) 2)Implement Runnable interface( java .lang. thread) Understand... Java Exception Thread     ... of this class is runnable 2. The Thread constructor is used to create an object
Java Thread : isDaemon() method
Java Thread : isDaemon() method In this section we are going to describe isDaemon() method with example in java thread. Daemon Thread  : In Java... Runnable { public void run() { Thread thread
Java Thread Interrupted
Java Thread Interrupted In this tutorial, you will learn how to interrupt a thread with example in Java. Thread Interrupt : Java thread facilitate you... implements Runnable { Thread thread; public ThreadInterrupt() { thread
Java Thread setName() Example
Java Thread setName() Example In this section we are going to describe setName() method with example in java thread. Thread setName() :  Suppose,  you want to change name of your thread so for that java thread provides
Java Thread Priority
Java Threads run with some priority There are Three types of Java Thread...() method. Java Thread Priority Example public class priority implements Runnable { @Override public void run() { for (int x = 1; x <= 3; x
Get Current Thread
. The thread in java is created and controlled by the java.lang.Threadclass. Two way to create Thread- 1)Implements Runnable interface. 2)By extending the ... have a class" Get Current Thread" implements Runnable interface.  1
Java Thread destroy
Java Thread destroy In this tutorial, we are using Thread.destroy() method to destroy the thread. Thread destroy() : Thread class provides destroy... implements Runnable{ public static void main(String args[]){ Thread thread
Java Current Thread
Java Current Thread In this tutorial, we are using Thread.currentThread() method to find the current thread name. Thread.currentThread() : Thread class provides method to display the current running thread. It is static Thread
Java :Thread Enumeration
Java :Thread Enumeration In this tutorial you will learn about java thread enumeration. Thread Enumeration : For enumeration, thread uses two methods... enumerate() method of thread. class ThreadEnumeration implements Runnable
java thread problem - Java Beginners
java thread problem  Hi Friends, My problem is related with java.util.concurrent.ThreadPoolExecutor I have a thread pool which using LinkedBlockingQueue to send some runnable object . Samples Code : ThreadPoolExecutor
Java :Thread Join
Java :Thread Join In this tutorial you will see how to use join method in java thread. join() method - join method waits until the thread die. If we... method of thread. public class ThreadJoin implements Runnable { Thread thread

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.