📚 Learning and exploring concurrency in Java.
This repository illustrates different concepts, patterns and examples via standalone subprojects. Each subproject is completely independent of the others and do not depend on the root project. This standalone subproject constraint forces the subprojects to be complete and maximizes the reader's chances of successfully running, understanding, and re-using the code.
The subprojects include:
A simple demonstration of virtual threads.
See the README in virtual-threads/.
Learning about interrupts https://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html.
See the README in interrupts/.
Simulate the execution of long-running work and show the power of CompletableFuture
to execute that work concurrently.
See the README in completable-future/.
Learning about java.util.Timer
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Timer.html.
and related APIs.
See the README in timer/.
Learning how signals, like SIGINT
, are handled by a Java program.
See the README in signals/.
General clean-ups, TODOs and things I wish to implement for this project:
- DONE Rename
loom
tovirtual-threads
- DONE Configure
loom/virtual-threads
as a Gradle subproject - DONE Upgrade to Gradle 8.5
- DONE Upgrade to Java 21
- DONE Unnest the
src/main/java
dirs in the non-Gradle native projects. We're only using Gradle as a way for the IDE to understand the project structure, but I don't want to pay the price of having to have asrc/main/java
dir in these projects. - DONE Move
mock-api
to mywiremock-playground
repo. I originally included it here as a way to explore completable futures with a workload I was familiar with in real work, but I can de-scope it now and instead create an in-process mock API using timers or something. Or better yet sleeps and virtual threads. - Show how to use
sun.misc.Signal
instead of just a shutdown hook. While thesun
package feels like an overall no-no because of the name plus the very frowned-uponsun.misc.Unsafe
,sun.misc.Signal
is a well-implemented, reasonable, and platform-independent thing/API and it's doubtful that it will be wholesale removed. I think there's just not enough motivation to change it. Maybe they'll move it to a different package some day. Either way, the API is great.