Created
July 27, 2020 14:59
-
-
Save AnjaliManhas/24bab1388d029f967b528b0fe5679e7b to your computer and use it in GitHub Desktop.
Multithreading executed by implementing runnable interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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