File tree Expand file tree Collapse file tree 1 file changed +2
-7
lines changed
core/src/main/java/dev/dotspace/common Expand file tree Collapse file tree 1 file changed +2
-7
lines changed Original file line number Diff line number Diff line change 88import java .util .Collection ;
99import java .util .Optional ;
1010import java .util .concurrent .CompletableFuture ;
11- import java .util .concurrent .ExecutorService ;
12- import java .util .concurrent .Executors ;
1311import java .util .concurrent .ThreadLocalRandom ;
1412
1513/**
1614 * Class with {@link Collection} operations
1715 */
1816@ NoArgsConstructor (access = AccessLevel .PRIVATE )
1917public final class SpaceCollections {
20- private final static ExecutorService SERVICE = Executors .newCachedThreadPool ();
21-
2218 /**
2319 * Get a random object of collection. Object wrapped in {@link Optional}
2420 *
@@ -46,8 +42,7 @@ public final class SpaceCollections {
4642 * or empty or if the given object is null in list.
4743 */
4844 public static <T > @ NotNull CompletableFuture <@ Nullable T > asyncRandom (final Collection <T > collection ) {
49- final CompletableFuture <@ Nullable T > completableFuture = new CompletableFuture <>(); //Create new completableFuture
50- SERVICE .execute (() -> completableFuture .complete (SpaceCollections .random (collection ).orElse (null ))); //Complete the future in a separate thread
51- return completableFuture ;
45+ return new CompletableFuture <@ Nullable T >()
46+ .completeAsync (() -> SpaceCollections .random (collection ).orElse (null )); //Complete the future in a separate thread
5247 }
5348}
You can’t perform that action at this time.
0 commit comments