JAVA-18116 Review log statements for projects - Week 7 - 2023 (#13583)

JAVA-18116 Review log statements for projects - Week 7 - 2023 (#13583)
---------

Co-authored-by: jogra <joseph.sterling.grah@miles.no>
This commit is contained in:
jsgrah-spring
2023-04-10 13:35:40 +02:00
committed by GitHub
parent 26790b429f
commit 23c1abe3f2
12 changed files with 99 additions and 23 deletions
@@ -1,9 +1,14 @@
package com.baeldung.concurrent.countdownlatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class Worker implements Runnable {
private static Logger log = LoggerFactory.getLogger(Worker.class);
private final List<String> outputScraper;
private final CountDownLatch countDownLatch;
@@ -15,7 +20,7 @@ public class Worker implements Runnable {
@Override
public void run() {
// Do some work
System.out.println("Doing some logic");
log.debug("Doing some logic");
outputScraper.add("Counted down");
countDownLatch.countDown();
}
@@ -1,8 +1,13 @@
package com.baeldung.concurrent.phaser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Phaser;
class LongRunningAction implements Runnable {
private static Logger log = LoggerFactory.getLogger(LongRunningAction.class);
private String threadName;
private Phaser ph;
@@ -14,18 +19,18 @@ class LongRunningAction implements Runnable {
@Override
public void run() {
System.out.println("This is phase " + ph.getPhase());
System.out.println("Thread " + threadName + " before long running action");
log.info("This is phase {}", ph.getPhase());
log.info("Thread {} before long running action", threadName);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Thread " + threadName + " action completed and waiting for others");
log.debug("Thread {} action completed and waiting for others", threadName);
ph.arriveAndAwaitAdvance();
System.out.println("Thread " + threadName + " proceeding in phase " + ph.getPhase());
log.debug("Thread {} proceeding in phase {}", threadName, ph.getPhase());
ph.arriveAndDeregister();
}