Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package experiments;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) throws Exception {
  8. Counter counter = new CounterImpl();
  9.  
  10. int numberOfThread = 1_000;
  11. Thread[] threads = new Thread[numberOfThread];
  12.  
  13. class CounterRunner implements Runnable {
  14. @Override
  15. public void run() {
  16. counter.count();
  17. }//end run
  18. }// end local class
  19.  
  20. for (int i = 0; i < threads.length; i++) {
  21. threads[i] = new Thread(new CounterRunner());
  22. threads[i].start();
  23. }//end for
  24.  
  25. // Wait for all sub-threads finish their task
  26. for (Thread thread : threads) {
  27. thread.join();
  28. }//end for
  29.  
  30. System.out.println("Count: " +counter.getCounter());
  31.  
  32. }//end main
  33.  
  34. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement