5
5
import java .nio .charset .UnsupportedCharsetException ;
6
6
import java .nio .file .Files ;
7
7
import java .nio .file .Path ;
8
+ import java .time .Duration ;
8
9
import java .util .List ;
9
10
import java .util .Optional ;
10
11
import java .util .concurrent .ExecutionException ;
@@ -138,6 +139,8 @@ public static String nameOfJava() {
138
139
return JavaPath .javaName ;
139
140
}
140
141
142
+ private static final Duration LONGEST_NS = Duration .ofNanos (Long .MAX_VALUE );
143
+
141
144
/**
142
145
* Wait (uninterruptibly) for some amount of time for the given process to finish.
143
146
*
@@ -146,6 +149,18 @@ public static String nameOfJava() {
146
149
* @return {@code true} if the process is still running after the elapsed time, or {@code false} if it has exited
147
150
*/
148
151
public static boolean stillRunningAfter (Process proc , long nanos ) {
152
+ return stillRunningAfter (proc , Duration .ofNanos (nanos ));
153
+ }
154
+
155
+ /**
156
+ * Wait (uninterruptibly) for some amount of time for the given process to finish.
157
+ *
158
+ * @param proc the process (must not be {@code null})
159
+ * @param time the amount of time to wait (must not be {@code null})
160
+ * @return {@code true} if the process is still running after the elapsed time, or {@code false} if it has exited
161
+ */
162
+ public static boolean stillRunningAfter (Process proc , Duration time ) {
163
+ long nanos = time .compareTo (LONGEST_NS ) > 0 ? Long .MAX_VALUE : time .toNanos ();
149
164
boolean intr = false ;
150
165
try {
151
166
long start = System .nanoTime ();
0 commit comments