Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public volatile static int COUNT = 4;
- public static void main(String[] args) throws InterruptedException {
- for (int i = 0; i < COUNT; i++) {
- SleepingThread sleepingThread = new SleepingThread();
- sleepingThread.join();
- //напишите тут ваш код
- }
- }
- public static class SleepingThread extends Thread {
- private static volatile int threadCount = 0;
- private volatile int countdownIndex = COUNT;
- public SleepingThread() {
- super(String.valueOf(++threadCount));
- start();
- }
- public void run() {
- while (true) {
- System.out.println(this);
- if (--countdownIndex == 0) return;
- //напишите тут ваш код
- try {
- Thread.sleep(10);
- }
- catch(InterruptedException e){
- System.out.println("Нить прервана");
- }
- }
- }
- public String toString() {
- return "#" + getName() + ": " + countdownIndex;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement