Java program on MultiThreading by extending Thread class Example 1
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 MyThread extends Thread {
public void run() {
System.out.println("Hello I am a thread (^-^)");
}
}
class ThreadingDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
System.out.println("Hi I am main (-_-)");
}
}
public void run() {
System.out.println("Hello I am a thread (^-^)");
}
}
class ThreadingDemo {
public static void main(String[] args) {
MyThread t = new MyThread();
t.start();
System.out.println("Hi I am main (-_-)");
}
}
OUTPUT:
Hi I am main (-_-)
Hello I am a thread (^-^)
Hello I am a thread (^-^)