Thread in Java
What is Thread?
Thread is a class, an independent path of execution within a program. A thread execute the provided code(Task) in new process, so the thread run concurrently with your program.
Usually thread is use for connectivity(i.e. Networking, Internet, Bluetooth), timer, i/o operation.
It can be extends with your program, and a run method must be override, and that override method run when thread starts.
Thread class is define in: java.lang.Thread
When thread object is made then a runnable object must pass inside thread object. I discuss runnable object in next lesson.
Example:
class ThreadTest extends Thread
{
public void run()
{
System.out.println("Thread starts...");
}
public static void main(String args[])
{
ThreadTest t=new ThreadTest();
t.start();
}
}
Thread is a class, an independent path of execution within a program. A thread execute the provided code(Task) in new process, so the thread run concurrently with your program.
Usually thread is use for connectivity(i.e. Networking, Internet, Bluetooth), timer, i/o operation.
It can be extends with your program, and a run method must be override, and that override method run when thread starts.
Thread class is define in: java.lang.Thread
When thread object is made then a runnable object must pass inside thread object. I discuss runnable object in next lesson.
Example:
class ThreadTest extends Thread
{
public void run()
{
System.out.println("Thread starts...");
}
public static void main(String args[])
{
ThreadTest t=new ThreadTest();
t.start();
}
}
No comments:
Post a Comment