What is Thread, How to Use Threads?
By Ramakrishna on Aug 15, 2008 in Thread Tutorial
Def. of Thread: A Thread represents a process (or)
execution of a statment one by one by the Microprocessor(JVM) is called Thread.
Note: Every java program will have a thread.
The basic usage of the thread is as follows:
In the most general sense, you can create a thread by instantiating an object of type thread.
There are two ways to create a new thread.
–> You can Extend the Thread class in your class and override the method run().
Syntax :
public class MyThread extends Thread
{
public void run()
{
——
}
}
–> You can implement the Runnable interface and use that class in the Thread constructor
Syntax :
public class MyThread implements Runnale
{
public void run()
{
——
}
}
