Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class Solution {
  2. public volatile static int COUNT = 4;
  3.  
  4. public static void main(String[] args) throws InterruptedException {
  5. for (int i = 0; i < COUNT; i++) {
  6. SleepingThread sleepingThread = new SleepingThread();
  7. sleepingThread.join();
  8.  
  9. //напишите тут ваш код
  10. }
  11. }
  12.  
  13. public static class SleepingThread extends Thread {
  14. private static volatile int threadCount = 0;
  15. private volatile int countdownIndex = COUNT;
  16.  
  17. public SleepingThread() {
  18. super(String.valueOf(++threadCount));
  19. start();
  20.  
  21. }
  22.  
  23. public void run() {
  24. while (true) {
  25. System.out.println(this);
  26. if (--countdownIndex == 0) return;
  27. //напишите тут ваш код
  28. try {
  29. Thread.sleep(10);
  30.  
  31. }
  32. catch(InterruptedException e){
  33. System.out.println("Нить прервана");
  34. }
  35. }
  36. }
  37.  
  38. public String toString() {
  39. return "#" + getName() + ": " + countdownIndex;
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement