Interrupted thread before logging (#3563)
This commit is contained in:
parent
43a4d08c36
commit
3e4b6df194
|
@ -1,7 +1,5 @@
|
||||||
package com.baeldung.concurrent.waitandnotify;
|
package com.baeldung.concurrent.waitandnotify;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
public class Data {
|
public class Data {
|
||||||
private String packet;
|
private String packet;
|
||||||
|
|
||||||
|
@ -14,6 +12,7 @@ public class Data {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
System.out.println("Thread Interrupted");
|
System.out.println("Thread Interrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +27,7 @@ public class Data {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
System.out.println("Thread Interrupted");
|
System.out.println("Thread Interrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ public class Receiver implements Runnable {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
|
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
System.out.println("Thread Interrupted");
|
System.out.println("Thread Interrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class Sender implements Runnable {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
|
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
System.out.println("Thread Interrupted");
|
System.out.println("Thread Interrupted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,8 @@ public class NetworkIntegrationTest {
|
||||||
sender.join();
|
sender.join();
|
||||||
receiver.join();
|
receiver.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
Thread.currentThread().interrupt();
|
||||||
|
System.out.println("Thread Interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(expected, outContent.toString());
|
assertEquals(expected, outContent.toString());
|
||||||
|
|
Loading…
Reference in New Issue