Java Thread and Runnable

Java Thread and Runnable

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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
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
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
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
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
java Thread
java Thread  what is purpose of Thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  What is the difference between process and thread
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What are the high-level thread states
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... implements Runnable{ Thread thread; public ThreadGetPriority(){ thread
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
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... implements Runnable { Thread thread = new Thread(); public ThreadSetPriority
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... in this state until you start the thread. Runnable : when you call start
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 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
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
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
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
Thread in java
Thread in java  which method will defined in thread class
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... implements Runnable { public void run() { System.out.println("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 threads ,java take long periods switching between threads , may be one
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... represents the run() method. public class ThreadRun implements Runnable { Thread
Java Thread
Java Thread       A java... sequential flow of control within a program. Programmer may use java thread mechanism... more at: http:/www.roseindia.net/java/thread/index.shtmlADS_TO_REPLACE_2
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 : 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... ThreadIsDaemon implements Runnable { public void run() { Thread thread
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 : 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... Runnable { Thread thread; public ThreadToString() { thread = new
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
How to Differenciate Main Thread and Child Thread in Java
Main Thread and Java Child Thread. Please Suggest any example or online link...({});   Hi, There are two types of Thread used in Java Programming Language. These are Java Main Thread and the Child Thread. The Below reference
Thread - Java Beginners
the concept of thread, thread creation and use of threads in JAVA application?  Thread creation and use of threads in JAVA Java Resourcehttp://www.roseindia.net/java/thread/thread-creation.shtml
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... implements Runnable { Thread thread; String name; ThreadJoin(String
Java thread state
Java thread state  what is Static binding
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
how to destroy java thread
how to destroy java thread  how to destroy java thread?   This will help .. Shutting Down the Java Thread
Java Thread : yield() method
Java Thread : yield() method In this section we are going to describe yield() method with example in java thread. yield() Method: When you want to stop...() method. public class ThreadYield implements Runnable { Thread thread
Java thread lock
Java thread lock  What happens when a thread cannot acquire a lock on an object
Java :Thread Enumeration
Java :Thread Enumeration In this tutorial you will learn about java thread enumeration. Thread Enumeration : For enumeration, thread uses two methods... implements Runnable { public void run() { Thread thread = Thread.currentThread
Java Thread IsInterrupt
Java Thread IsInterrupt In this section we are going to describe isInterrupt() method with example in java thread. Thread IsInterrupt : If you want... ThreadIsInterrupt implements Runnable { Thread thread; public ThreadIsInterrupt

Ads