[JAVA-13958] Minor style changes + aligned code with article (#12889)

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
panos-kakos 2022-11-05 09:58:01 +00:00 committed by GitHub
parent adbb7e27bc
commit 7313894322
5 changed files with 43 additions and 44 deletions

View File

@ -12,8 +12,9 @@ public class Data {
try { try {
wait(); wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread()
System.out.println("Thread Interrupted"); .interrupt();
System.err.println("Thread Interrupted");
} }
} }
transfer = true; transfer = true;
@ -28,8 +29,9 @@ public class Data {
try { try {
wait(); wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread()
System.out.println("Thread Interrupted"); .interrupt();
System.err.println("Thread Interrupted");
} }
} }
transfer = false; transfer = false;

View File

@ -10,18 +10,18 @@ public class Receiver implements Runnable {
} }
public void run() { public void run() {
for(String receivedMessage = load.receive(); for (String receivedMessage = load.receive(); !"End".equals(receivedMessage); receivedMessage = load.receive()) {
!"End".equals(receivedMessage) ;
receivedMessage = load.receive()) {
System.out.println(receivedMessage); System.out.println(receivedMessage);
//Thread.sleep() to mimic heavy server-side processing //Thread.sleep() to mimic heavy server-side processing
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(); Thread.currentThread()
System.out.println("Thread Interrupted"); .interrupt();
System.err.println("Thread Interrupted");
} }
} }
} }

View File

@ -10,23 +10,19 @@ public class Sender implements Runnable {
} }
public void run() { public void run() {
String packets[] = { String packets[] = { "First packet", "Second packet", "Third packet", "Fourth packet", "End" };
"First packet",
"Second packet",
"Third packet",
"Fourth packet",
"End"
};
for (String packet : packets) { for (String packet : packets) {
data.send(packet); data.send(packet);
//Thread.sleep() to mimic heavy server-side processing //Thread.sleep() to mimic heavy server-side processing
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(); Thread.currentThread()
System.out.println("Thread Interrupted"); .interrupt();
System.err.println("Thread Interrupted");
} }
} }
} }

View File

@ -57,8 +57,9 @@ public class NetworkIntegrationTest {
sender.join(); sender.join();
receiver.join(); receiver.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread()
System.out.println("Thread Interrupted"); .interrupt();
System.err.println("Thread Interrupted");
} }
assertEquals(expected, outContent.toString()); assertEquals(expected, outContent.toString());