//Bless anyone who decides to follow this path
Multithreading is a model of program execution
that allows for multiple threads to be created
within a process, executing independently but
concurrently sharing process resources.
Depending on the hardware, threads can run
fully parallel if they are distributed to their own CPU core.
//Using Thread Class
public class MultiThreadinng extends Thread{
public static void main(String[] args) throws InterruptedException{
MultiThreadinng mt = new MultiThreadinng();
mt.start();
for(int j=0; j<200; j++){
System.out.print("j: "+ j+" ");
Thread.sleep(1000);
}
}
public void run(){
for(int i=0; i<200; i++){
System.out.print("i: "+ i+" ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class MultithreadingDemo extends Thread{
public void run(){
System.out.println("My thread is in running state.");
}
public static void main(String args[]){
MultithreadingDemo obj=new MultithreadingDemo();
obj.start();
}
}