Advertisement
apl-mhd

ThreadJoin

Jan 6th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.awt.image.ImagingOpException;
  4.  
  5. public class ThreadJoin implements Runnable {
  6.  
  7.      static  int count=0;
  8.     @Override
  9.     public void run() {
  10.  
  11.         for (int i=0; i<1000000; i++)
  12.             count++;
  13.     }
  14.  
  15.  
  16.     public static void main(String[] args) throws Exception {
  17.  
  18.     Thread  t1 = new Thread(new ThreadJoin());
  19.     Thread  t2 = new Thread(new ThreadJoin());
  20.  
  21.         t1.start();
  22.         t2.start();
  23.  
  24.         try {
  25.  
  26.             t1.join();
  27.             t2.join();
  28.         }catch (Exception e) {e.printStackTrace();}
  29.  
  30.         System.out.println("End thread "+count);
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement