You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/08/21 19:22:29 UTC

[commons-lang] 01/02: Add ThreadUtils.sleepQuietly(Duration)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit f8df864f4cde9d8c6a21ba04ecfe9abd286de71d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 21 15:17:44 2022 -0400

    Add ThreadUtils.sleepQuietly(Duration)
    
    Remove new ThreadUtils.sleepQuietly(long)
---
 src/changes/changes.xml                                        |  2 +-
 src/main/java/org/apache/commons/lang3/ThreadUtils.java        | 10 +++++-----
 src/test/java/org/apache/commons/lang3/time/StopWatchTest.java |  8 ++++----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fa7d08420..9b465ff50 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -110,7 +110,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.newInstance(Class&gt;T>, int).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use null-safe Streams.of(T...).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ClassUtils.comparator().</action>
-    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ThreadUtils.sleepQuietly(long).</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ThreadUtils.sleepQuietly(Duration).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], IntFunction).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.setAll(T[], Supplier).</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanConsumer.</action>
diff --git a/src/main/java/org/apache/commons/lang3/ThreadUtils.java b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
index 362b32ac2..048842d21 100644
--- a/src/main/java/org/apache/commons/lang3/ThreadUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
@@ -554,17 +554,17 @@ public class ThreadUtils {
     }
 
     /**
-     * Sleeps for the given amount of milliseconds while ignoring {@link InterruptedException}.
+     * Sleeps for the given duration while ignoring {@link InterruptedException}.
      * <p>
-     * The sleep duration may be shorter than {@code millis} if we catch a {@link InterruptedException}.
+     * The sleep duration may be shorter than duration if we catch a {@link InterruptedException}.
      * </p>
      *
-     * @param millis the length of time to sleep in milliseconds
+     * @param duration the length of time to sleep.
      * @since 3.13.0
      */
-    public static void sleepQuietly(final long millis) {
+    public static void sleepQuietly(final Duration duration) {
         try {
-            sleep(Duration.ofMillis(millis));
+            sleep(duration);
         } catch (final InterruptedException e) {
             // be quiet.
         }
diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
index 503459ea7..69ac71dcd 100644
--- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
@@ -32,14 +32,14 @@ import org.apache.commons.lang3.reflect.FieldUtils;
 import org.junit.jupiter.api.Test;
 
 /**
- * TestCase for StopWatch.
+ * Tests {@link StopWatch}.
  */
 public class StopWatchTest extends AbstractLangTest {
 
     private static final Duration MILLIS_200 = Duration.ofMillis(200);
     private static final Duration MILLIS_550 = Duration.ofMillis(550);
     private static final String MESSAGE = "Baking cookies";
-    private static final int MIN_SLEEP_MILLISECONDS = 20;
+    private static final Duration MIN_SLEEP = Duration.ofMillis(20);
     private static final String ZERO_HOURS_PREFIX = "00:";
     private static final String ZERO_TIME_ELAPSED = "00:00:00.000";
 
@@ -144,7 +144,7 @@ public class StopWatchTest extends AbstractLangTest {
     @Test
     public void testFormatSplitTime() {
         final StopWatch watch = StopWatch.createStarted();
-        ThreadUtils.sleepQuietly(MIN_SLEEP_MILLISECONDS);
+        ThreadUtils.sleepQuietly(MIN_SLEEP);
         watch.split();
         final String formatSplitTime = watch.formatSplitTime();
         assertNotEquals(ZERO_TIME_ELAPSED, formatSplitTime);
@@ -155,7 +155,7 @@ public class StopWatchTest extends AbstractLangTest {
     public void testFormatSplitTimeWithMessage() {
         final StopWatch watch = new StopWatch(MESSAGE);
         watch.start();
-        ThreadUtils.sleepQuietly(MIN_SLEEP_MILLISECONDS);
+        ThreadUtils.sleepQuietly(MIN_SLEEP);
         watch.split();
         final String formatSplitTime = watch.formatSplitTime();
         assertFalse(formatSplitTime.startsWith(MESSAGE), formatSplitTime);