Multithreading
Multithreading is a Java feature that allows concurrent execution of two or more parts of a program.Creating Threads
1. Extend Thread Class:public class Main extends Thread {
public void run() {
System.out.println("This code is running in a thread");
}
}
2. Implement Runnable Interface:
public class Main implements Runnable {
public void run() {
System.out.println("This code is running in a thread");
}
}
Running Threads
Main thread = new Main();
thread.start();