2222/**
2323 * Monitors a thread, interrupting it if it reaches the specified timeout.
2424 * <p>
25- * This works by sleeping until the specified timeout amount and then
26- * interrupting the thread being monitored. If the thread being monitored
27- * completes its work before being interrupted, it should {@code interrupt()}
28- * the <i>monitor</i> thread.
25+ * This works by sleeping until the specified timeout amount and then interrupting the thread being monitored. If the
26+ * thread being monitored completes its work before being interrupted, it should {@code interrupt()} the <i>monitor</i>
27+ * thread.
2928 * </p>
3029 *
3130 * <pre>
32- * Duration timeout = Duration.ofSeconds(1);
33- * try {
34- * Thread monitor = ThreadMonitor.start(timeout);
35- * // do some work here
36- * ThreadMonitor.stop(monitor);
37- * } catch (InterruptedException e) {
38- * // timed amount was reached
39- * }
31+ * Duration timeout = Duration.ofSeconds(1);
32+ * try {
33+ * Thread monitor = ThreadMonitor.start(timeout);
34+ * // do some work here
35+ * ThreadMonitor.stop(monitor);
36+ * } catch (InterruptedException e) {
37+ * // timed amount was reached
38+ * }
4039 * </pre>
4140 *
4241 */
@@ -48,10 +47,8 @@ class ThreadMonitor implements Runnable {
4847 /**
4948 * Start monitoring the current thread.
5049 *
51- * @param timeout The timeout amount.
52- * or no timeout if the value is zero or less
53- * @return The monitor thread or {@code null}
54- * if the timeout amount is not greater than zero
50+ * @param timeout The timeout amount. or no timeout if the value is zero or less.
51+ * @return The monitor thread or {@code null} if the timeout amount is not greater than zero.
5552 */
5653 static Thread start (final Duration timeout ) {
5754 return start (Thread .currentThread (), timeout );
@@ -61,10 +58,8 @@ static Thread start(final Duration timeout) {
6158 * Start monitoring the specified thread.
6259 *
6360 * @param thread The thread The thread to monitor
64- * @param timeout The timeout amount.
65- * or no timeout if the value is zero or less
66- * @return The monitor thread or {@code null}
67- * if the timeout amount is not greater than zero
61+ * @param timeout The timeout amount. or no timeout if the value is zero or less.
62+ * @return The monitor thread or {@code null} if the timeout amount is not greater than zero.
6863 */
6964 static Thread start (final Thread thread , final Duration timeout ) {
7065 if (timeout .isZero () || timeout .isNegative ()) {
@@ -100,8 +95,7 @@ private ThreadMonitor(final Thread thread, final Duration timeout) {
10095 }
10196
10297 /**
103- * Sleep until the specified timeout amount and then
104- * interrupt the thread being monitored.
98+ * Sleep until the specified timeout amount and then interrupt the thread being monitored.
10599 *
106100 * @see Runnable#run()
107101 */
@@ -118,8 +112,8 @@ public void run() {
118112 /**
119113 * Sleeps for a guaranteed minimum duration unless interrupted.
120114 *
121- * This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else
122- * it deems appropriate. Read {@link Thread#sleep(long, int)}} for further interesting details.
115+ * This method exists because Thread.sleep(100) can sleep for 0, 70, 100 or 200ms or anything else it deems appropriate.
116+ * Read {@link Thread#sleep(long, int)}} for further interesting details.
123117 *
124118 * @param duration the sleep duration.
125119 * @throws InterruptedException if interrupted
@@ -136,4 +130,4 @@ private static void sleep(final Duration duration) throws InterruptedException {
136130 private static int getNanosOfMiili (final Duration duration ) {
137131 return duration .getNano () % 1_000_000 ;
138132 }
139- }
133+ }
0 commit comments