QuizMain.java 827 B

123456789101112131415161718192021222324252627282930313233
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. public class Main {
  4. public static final int BIG_NR = 2000000;
  5. public static long bigSum;
  6. public static void main(String[] args) {
  7. List<Thread> threads =
  8. new ArrayList<Thread>();
  9. for (int i = 0; i < 50; i++) {
  10. Runnable task = new Sum(BIG_NR);
  11. Thread worker = new Thread(task);
  12. worker.start();
  13. threads.add(worker);
  14. }
  15. int running = 0;
  16. do {
  17. running = 0;
  18. for (Thread thread : threads) {
  19. if (thread.isAlive()) {
  20. running++;
  21. }
  22. }
  23. System.out.println("Remaining threads: " + running);
  24. } while (running > 0);
  25. System.out.println(Main.bigSum);
  26. }
  27. }