JDK21 has structured concurrency. It works with virtual threads so the main task will be moved aside (from the OS thread) until the sub tasks finnish.
https://www.infoq.com/news/2023/06/structured-concurrency-jd...
https://www.infoq.com/news/2023/06/structured-concurrency-jd...