...
There is no explicit support in the current prototype but it is possible to use existing constructs without needing too many new APIs. In particular, ExecutorService has been retrofitted to extend AutoCloseable so that it’s possible to write code like this and Executors has been updated to define a number of static factory methods that support usage in a structured manner. Here's an example:
ThreadFactory factory = Thread.ofVirtual().factory()try (ExecutorService executor = Executors.newThreadExecutor(factory)) {executor.submit(task1);executor.submit(task2);}
A thread executing this code The thread that invokes Executors.newThreadExecutor is owner of the thread executor. It's the only thread can be call the shutdown, shutdownNow or close methods. The thread will block in the executor’s close method until the two tasks have have completed and executor has terminated.
...