Skip to content

Instantly share code, notes, and snippets.

@AnjaliManhas
Created July 27, 2020 14:59
Show Gist options
  • Save AnjaliManhas/24bab1388d029f967b528b0fe5679e7b to your computer and use it in GitHub Desktop.
Save AnjaliManhas/24bab1388d029f967b528b0fe5679e7b to your computer and use it in GitHub Desktop.
Multithreading executed by implementing runnable interface
package com.wordpress.compilationerrors;
import java.lang.Thread;
import java.lang.Runnable;
class MultithreadingDemo implements Runnable {
public void run(){
try {
System.out.println("Thread"+ Thread.currentThread().getId()+" is running");
}
catch(Exception e){
System.out.println("Exception is caught");
}
}
}
public class Main {
public static void main(String[] args) {
// write your code here
int n = 8; //no. of threads
for(int i = 0; i < n; i++){
Thread obj = new Thread(new MultithreadingDemo());
obj.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment