<div dir="auto"><div>> I don't think that is "leaking" in the way a leak is typically considered (i.e. a memory leak)</div><div dir="auto"><br></div><div dir="auto">It is also very common to an exposure of unintended information "leaking" (e.g. "leaking internal state")</div><div dir="auto"><br></div><div dir="auto">That being said, CompletableFuture doesn't leak anything and there isn't any problems in the executor using this instead of plain Future <br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Mar 15, 2023, 00:43 Paul Bjorkstrand <<a href="mailto:paul.bjorkstrand@gmail.com">paul.bjorkstrand@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">That is not unique to Executors.newVirtualThreadPerTaskExecutor. It is also the same Executors.newThreadPerTaskExecutor. Both use the same ThreadPerTaskExecutor (with different thread factories) that returns instances of ThreadBoundFuture, which extends CompletableFuture [1], for calls to the submit(..) methods.<div><br></div><div>I don't think that is "leaking" in the way a leak is typically considered (i.e. a memory leak). It may be "leaking" some information about the implementation, but that is just a consequence of an open, inspectable system like the JDK.</div><div><br></div><div>[1]: <a href="https://github.com/openjdk/loom/blob/fibers/src/java.base/share/classes/java/util/concurrent/ThreadPerTaskExecutor.java#L327" target="_blank" rel="noreferrer">https://github.com/openjdk/loom/blob/fibers/src/java.base/share/classes/java/util/concurrent/ThreadPerTaskExecutor.java#L327</a></div><div><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr"><div><div><br></div>-Paul</div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 14, 2023 at 3:41 PM Kasper Nielsen <<a href="mailto:kasperni@gmail.com" target="_blank" rel="noreferrer">kasperni@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I don't know if it is much of an issue in practice but you can cast the<br>
futures returned from Executors.newVirtualThreadPerTaskExecutor<br>
to CompletableFuture:<br>
<br>
ExecutorService e = Executors.newVirtualThreadPerTaskExecutor();<br>
CompletableFuture f = (CompletableFuture<?>) e.submit(() -> {});<br>
<br>
Other executors return instances of FutureTask which is probably less<br>
likely to be abused.<br>
<br>
/Kasper<br>
</blockquote></div>
</blockquote></div></div></div>