From ca8e33e3390daf53fe089b56421695d235536875 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Sun, 6 Nov 2022 18:33:13 +0000 Subject: [PATCH] [JAVA-13959] Alligned code with article (#12982) Co-authored-by: panagiotiskakos --- .../threadjoin}/ThreadJoinUnitTest.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) rename core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/{thread/join => concurrent/threadjoin}/ThreadJoinUnitTest.java (68%) diff --git a/core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java b/core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/concurrent/threadjoin/ThreadJoinUnitTest.java similarity index 68% rename from core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java rename to core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/concurrent/threadjoin/ThreadJoinUnitTest.java index dc30ce6c74..10d566de96 100644 --- a/core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/thread/join/ThreadJoinUnitTest.java +++ b/core-java-modules/core-java-concurrency-simple/src/test/java/com/baeldung/concurrent/threadjoin/ThreadJoinUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.thread.join; +package com.baeldung.concurrent.threadjoin; import org.junit.Ignore; import org.junit.Test; @@ -21,49 +21,47 @@ public class ThreadJoinUnitTest { SampleThread(int processingCount) { this.processingCount = processingCount; - LOGGER.debug("Thread " + this.getName() + " created"); + LOGGER.info("Thread " + this.getName() + " created"); } @Override public void run() { - LOGGER.debug("Thread " + this.getName() + " started"); + LOGGER.info("Thread " + this.getName() + " started"); while (processingCount > 0) { try { Thread.sleep(1000); // Simulate some work being done by thread } catch (InterruptedException e) { - LOGGER.debug("Thread " + this.getName() + " interrupted."); + LOGGER.info("Thread " + this.getName() + " interrupted."); } processingCount--; - LOGGER.debug("Inside Thread " + this.getName() + ", processingCount = " + processingCount); + LOGGER.info("Inside Thread " + this.getName() + ", processingCount = " + processingCount); } - LOGGER.debug("Thread " + this.getName() + " exiting"); + LOGGER.info("Thread " + this.getName() + " exiting"); } } @Test public void givenNewThread_whenJoinCalled_returnsImmediately() throws InterruptedException { Thread t1 = new SampleThread(0); - LOGGER.debug("Invoking join."); + LOGGER.info("Invoking join"); t1.join(); - LOGGER.debug("Returned from join"); - LOGGER.debug("Thread state is" + t1.getState()); + LOGGER.info("Returned from join"); + LOGGER.info("Thread state is" + t1.getState()); assertFalse(t1.isAlive()); } @Test - public void givenStartedThread_whenJoinCalled_waitsTillCompletion() - throws InterruptedException { + public void givenStartedThread_whenJoinCalled_waitsTillCompletion() throws InterruptedException { Thread t2 = new SampleThread(1); t2.start(); - LOGGER.debug("Invoking join."); + LOGGER.info("Invoking join"); t2.join(); - LOGGER.debug("Returned from join"); + LOGGER.info("Returned from join"); assertFalse(t2.isAlive()); } @Test - public void givenStartedThread_whenTimedJoinCalled_waitsUntilTimedout() - throws InterruptedException { + public void givenStartedThread_whenTimedJoinCalled_waitsUntilTimedout() throws InterruptedException { Thread t3 = new SampleThread(10); t3.start(); t3.join(1000); @@ -72,19 +70,17 @@ public class ThreadJoinUnitTest { @Test @Ignore - public void givenThreadTerminated_checkForEffect_notGuaranteed() - throws InterruptedException { + public void givenThreadTerminated_checkForEffect_notGuaranteed() throws InterruptedException { SampleThread t4 = new SampleThread(10); t4.start(); - //not guaranteed to stop even if t4 finishes. + //not guaranteed to stop even if t4 finishes. do { } while (t4.processingCount > 0); } @Test - public void givenJoinWithTerminatedThread_checkForEffect_guaranteed() - throws InterruptedException { + public void givenJoinWithTerminatedThread_checkForEffect_guaranteed() throws InterruptedException { SampleThread t4 = new SampleThread(10); t4.start(); do {