File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/main/java/com/github/underscore Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -2098,13 +2098,14 @@ public static <T> java.util.concurrent.ScheduledFuture<T> delay(
20982098 final Supplier <T > function , final int delayMilliseconds ) {
20992099 final java .util .concurrent .ScheduledExecutorService scheduler =
21002100 java .util .concurrent .Executors .newSingleThreadScheduledExecutor ();
2101- final java .util .concurrent .ScheduledFuture <T > future =
2102- scheduler .schedule (
2103- function ::get ,
2104- delayMilliseconds ,
2105- java .util .concurrent .TimeUnit .MILLISECONDS );
2106- scheduler .shutdown ();
2107- return future ;
2101+ try {
2102+ return scheduler .schedule (
2103+ function ::get ,
2104+ delayMilliseconds ,
2105+ java .util .concurrent .TimeUnit .MILLISECONDS );
2106+ } finally {
2107+ scheduler .shutdown ();
2108+ }
21082109 }
21092110
21102111 public static <T > java .util .concurrent .ScheduledFuture <T > defer (final Supplier <T > function ) {
@@ -3624,6 +3625,7 @@ public static <T> java.util.concurrent.ScheduledFuture setInterval(
36243625 final Supplier <T > function , final int delayMilliseconds ) {
36253626 final java .util .concurrent .ScheduledExecutorService scheduler =
36263627 java .util .concurrent .Executors .newSingleThreadScheduledExecutor ();
3628+ Runtime .getRuntime ().addShutdownHook (new Thread (scheduler ::shutdown ));
36273629 return scheduler .scheduleAtFixedRate (
36283630 function ::get ,
36293631 delayMilliseconds ,
You can’t perform that action at this time.
0 commit comments