Skip to content

Commit

Permalink
Interrupted thread before logging (eugenp#3563)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramansahasi authored and maibin committed Jan 31, 2018
1 parent 43a4d08 commit 3e4b6df
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.baeldung.concurrent.waitandnotify;

import org.slf4j.Logger;

public class Data {
private String packet;

Expand All @@ -14,6 +12,7 @@ public synchronized String receive() {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Thread Interrupted");
}
}
Expand All @@ -28,6 +27,7 @@ public synchronized void send(String packet) {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Thread Interrupted");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void run() {
try {
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Thread Interrupted");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void run() {
try {
Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Thread Interrupted");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void givenSenderAndReceiver_whenSendingPackets_thenNetworkSynchronized()
sender.join();
receiver.join();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
System.out.println("Thread Interrupted");
}

assertEquals(expected, outContent.toString());
Expand Down

0 comments on commit 3e4b6df

Please sign in to comment.