Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package com.javarush.task.task16.task1623;
  2.  
  3. /*
  4. Рекурсивное создание нитей
  5. */
  6.  
  7. public class Solution {
  8. static int count = 15;
  9. static volatile int countCreatedThreads;
  10.  
  11. public static void main(String[] args) {
  12. System.out.println(new GenerateThread());
  13. }
  14.  
  15. public static class GenerateThread extends Thread {
  16.  
  17. @Override
  18.  
  19. public String toString() {
  20. return (getName() + " created");
  21. }
  22.  
  23. public GenerateThread () {
  24.  
  25. super(String.valueOf(++countCreatedThreads));
  26. start();
  27. }
  28. public void run() {
  29. if (countCreatedThreads < (Solution.count)) {
  30. new GenerateThread();
  31. System.out.println(this);
  32.  
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement