Effects and concurrency

A program that talks to the outside world has to deal with things that fail, take time and happen at once. This part takes them in the order a program meets them: an exception and the resource that must be closed anyway, a computation that finishes later and the promise behind it, the pool of threads that runs it, the virtual threads of JDK 21 that make a million of them cheap, the file and the child process, and the HTTP client of the standard library.

Every program here runs on its own: the futures are awaited, the threads are joined and the HTTP server is started inside the program on a free local port, so no output depends on the order two threads happened to run in. That is also the habit the part teaches: concurrency whose result is deterministic is concurrency a reader can check.

058 Exceptions and Using try, catch and finally, Try, and a resource that closes itself Open 059 Future and Promise a Future, the Promise behind it, map and flatMap, and Await Open 060 Execution contexts the global pool, a fixed pool, and why blocking belongs on its own Open 061 Virtual threads Thread.ofVirtual on JDK 21, many tasks at once, and the platform thread underneath Open 062 Files and processes java.nio.file, Files.readString and writeString, ProcessBuilder and the exit status Open 063 The HTTP client java.net.http.HttpClient against a local server, or the honest reason it cannot run here Open

Lessons