Advertisement
sriyanto

multi

Feb 14th, 2024
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. // Java code for thread creation by implementing
  2. // the Runnable Interface
  3. class MultithreadingDemo implements Runnable {
  4.     public void run() {
  5.         try {
  6.             // Displaying the thread that is running
  7.             System.out.println(
  8.                     "Thread " + Thread.currentThread()
  9.                             + " is running");
  10.         } catch (Exception e) {
  11.             // Throwing an exception
  12.             System.out.println("Exception is caught");
  13.         }
  14.     }
  15. }
  16.  
  17. // Main Class
  18. class Multithread {
  19.     public static void main(String[] args) {
  20.         int n = 8; // Number of threads
  21.         for (int i = 0; i < n; i++) {
  22.             Thread object = new Thread(new MultithreadingDemo());
  23.             object.start();
  24.         }
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement