I am trying to figure out how to work with virtual threads yet still use ThreadPoolExecutor#beforeExecute.
My older code simply extends ThreadPoolExecutor, but its constructor takes core/max pool size, a queue, which are stuff I assume you should not use or need in virtual threads.
Is there a way to enjoy the beforeExecute with virtual threads?
You can abuse a
ThreadPoolExecutorto create a new virtual thread per task without an actual pool, likehowever, there is no need for such an approach when all you want, is to have a hook to be executed before each task: