This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CompletableFuture<String> completableFuture = new CompletableFuture<>(); | |
| completableFuture | |
| .thenAccept(System.out::println); | |
| completableFuture.complete("I have completed!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final ExecutorService executor = Executors.newSingleThreadExecutor(); | |
| CompletableFuture.runAsync(task, executor); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Runnable task = () -> { | |
| System.out.println("Async task thread : " + Thread.currentThread().getName()); | |
| System.out.println("EXECUTED!"); | |
| }; | |
| final CompletableFuture<Void> future = CompletableFuture.runAsync(task); | |
| System.out.println("Main thread : " + Thread.currentThread().getName()); | |
| future.join(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Runnable task = () -> System.out.println("EXECUTED!"); | |
| CompletableFuture.runAsync(task); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyClass { | |
| private MyAppState myAppState; | |
| synchronized public void pleaseBlockMe() { | |
| // omitted code | |
| updateState(); | |
| // omitted code | |
| } | |
| private void updateState() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import java.time.LocalTime; | |
| import java.util.Collection; | |
| import java.util.List; | |
| import java.util.concurrent.CompletableFuture; | |
| import java.util.concurrent.Executor; | |
| import java.util.concurrent.TimeUnit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void convert_shouldReturnDCCCXXXVIII() { | |
| final String romanNumeral = RomanNumerals.convert(838); | |
| assertThat(romanNumeral, is("DCCCXXXVIII")); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| public void convert_shouldReturnVI() { | |
| final String romanNumeral = RomanNumerals.convert(6); | |
| assertThat(romanNumeral, is("VI")); | |
| } |