diff --git a/src/main/java/ru/j4j/concurrent/ConsoleProgress.java b/src/main/java/ru/j4j/concurrent/ConsoleProgress.java index e2a4c78..e041f8b 100644 --- a/src/main/java/ru/j4j/concurrent/ConsoleProgress.java +++ b/src/main/java/ru/j4j/concurrent/ConsoleProgress.java @@ -16,7 +16,7 @@ public void run() { i = 0; } } catch (InterruptedException e) { - break; + Thread.currentThread().interrupt(); } } } diff --git a/src/main/java/ru/j4j/concurrent/ThreadStop.java b/src/main/java/ru/j4j/concurrent/ThreadStop.java index 1b65323..42874e7 100644 --- a/src/main/java/ru/j4j/concurrent/ThreadStop.java +++ b/src/main/java/ru/j4j/concurrent/ThreadStop.java @@ -1,16 +1,24 @@ package ru.j4j.concurrent; - public class ThreadStop { public static void main(String[] args) throws InterruptedException { - Thread first = new Thread(() -> { - int counter = 0; - while (!Thread.currentThread().isInterrupted()) { - System.out.println(counter++); - } - }); - first.start(); + Thread progress = new Thread( + () -> { + while (!Thread.currentThread().isInterrupted()) { + try { + System.out.println("start ..."); + Thread.sleep(10000); + } catch (InterruptedException e) { + System.out.println("Thread is interrupted: " + Thread.currentThread().isInterrupted()); + System.out.println("Thread state: " + Thread.currentThread().getState()); + Thread.currentThread().interrupt(); + } + } + } + ); + progress.start(); Thread.sleep(1000); - first.interrupt(); + progress.interrupt(); + progress.join(); } -} +} \ No newline at end of file