Java Program on Multithreading by extending Thread class Example 2
THREAD:
A thread is a light-weight smallest part of a process that can run concurrently with the other threads of the same process. All threads of a process share the common memory.MULTITHREADING:
The process of executing multiple threads simultaneously is known as multithreading.
PROGRAM:
class ThreadOne extends Thread {
ThreadOne() {
System.out.println("Hey I'm Constructor (o_o)");
start();
}
public void run() {
System.out.println("Hello I am a thread (^-^)");
}
}
class ThreadingDemo {
public static void main(String[] args) {
ThreadOne t = new ThreadOne();
System.out.println("Hi I am main (-_-)");
}
}
ThreadOne() {
System.out.println("Hey I'm Constructor (o_o)");
start();
}
public void run() {
System.out.println("Hello I am a thread (^-^)");
}
}
class ThreadingDemo {
public static void main(String[] args) {
ThreadOne t = new ThreadOne();
System.out.println("Hi I am main (-_-)");
}
}
OUTPUT:
Hey I'm Constructor (o_o)
Hi I am main (-_-)
Hello I am a thread (^-^)
Hi I am main (-_-)
Hello I am a thread (^-^)