...
Code Block | ||
---|---|---|
| ||
try (ExecutorService executor = Executors.newUnboundedVirtualThreadExecutornewVirtualThreadExecutor()) { executor.execute(() -> System.out.println("Hello")); executor.execute(() -> System.out.println("Hi")); } |
...
Code Block | ||
---|---|---|
| ||
try (ExecutorService executor = Executors.newUnboundedVirtualThreadExecutornewVirtualThreadExecutor()) { Callable<String> task1 = () -> "foo"; Callable<String> task2 = () -> "bar"; Callable<String> task3 = () -> "baz"; String result = executor.invokeAny(List.of(task1, task2, task3)); } |
...
Code Block | ||
---|---|---|
| ||
try (ExecutorService executor = Executors.newUnboundedVirtualThreadExecutornewVirtualThreadExecutor()) { Callable<String> task1 = () -> "foo"; Callable<String> task2 = () -> "bar"; Callable<String> task3 = () -> "baz"; List<CompletableFuture<String>> cfs = executor.submitTasks(List.of(task1, task2, task3)); CompletableFuture.stream(cfs) .map(CompletableFuture::join) .forEach(System.out::println); } |
...
Code Block | ||
---|---|---|
| ||
Instant deadline = Instant.now().plusSeconds(30); try (ExecutorService executor = Executors.newUnboundedVirtualThreadExecutornewVirtualThreadExecutor().withDeadline(deadline)) { : } |
...
Overview
Content Tools
ThemeBuilder