File tree Expand file tree Collapse file tree
core-java-concurrency/src
main/java/com/baeldung/concurrent/waitandnotify
test/java/com/baeldung/concurrent/waitandnotify Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .baeldung .concurrent .waitandnotify ;
22
3- import org .slf4j .Logger ;
4-
53public class Data {
64 private String packet ;
75
@@ -14,6 +12,7 @@ public synchronized String receive() {
1412 try {
1513 wait ();
1614 } catch (InterruptedException e ) {
15+ Thread .currentThread ().interrupt ();
1716 System .out .println ("Thread Interrupted" );
1817 }
1918 }
@@ -28,6 +27,7 @@ public synchronized void send(String packet) {
2827 try {
2928 wait ();
3029 } catch (InterruptedException e ) {
30+ Thread .currentThread ().interrupt ();
3131 System .out .println ("Thread Interrupted" );
3232 }
3333 }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public void run() {
2020 try {
2121 Thread .sleep (ThreadLocalRandom .current ().nextInt (1000 , 5000 ));
2222 } catch (InterruptedException e ) {
23+ Thread .currentThread ().interrupt ();
2324 System .out .println ("Thread Interrupted" );
2425 }
2526 }
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public void run() {
2525 try {
2626 Thread .sleep (ThreadLocalRandom .current ().nextInt (1000 , 5000 ));
2727 } catch (InterruptedException e ) {
28+ Thread .currentThread ().interrupt ();
2829 System .out .println ("Thread Interrupted" );
2930 }
3031 }
Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ public void givenSenderAndReceiver_whenSendingPackets_thenNetworkSynchronized()
5757 sender .join ();
5858 receiver .join ();
5959 } catch (InterruptedException e ) {
60- e .printStackTrace ();
60+ Thread .currentThread ().interrupt ();
61+ System .out .println ("Thread Interrupted" );
6162 }
6263
6364 assertEquals (expected , outContent .toString ());
You can’t perform that action at this time.
0 commit comments