ExecutorService with try-with resources

1 day ago 1
ARTICLE AD BOX

I was working on a project with my buddy and had to use concurrency for a file downloader.

Naturally I went for ExecutorService.

My code looked something like

try(ExecutorService service = Executors.newVirtualThreadPerTaskExecutor()) { //Download logic }

My buddy saw this and advised "I don't recommend using ExecutorService with try-with resources"

Why is this? The ExecutorService implements Autoclosable doesn't it? Even IntelliJ gives the hint when I use it without try-with resources.

Read Entire Article