Na aula "02 Simulando uma aplicação com muitas threads" não consigo compilar o try with resources.
Erro: Required type: AutoCloseable Provided: ExecutorService
ou ainda: Incompatible types. Found: 'java.util.concurrent.ExecutorService', required: 'java.lang.AutoCloseable'
Minha classe completa:
package br.com.alura;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TesteMultiplasThreads {
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool( 10000);
Instant inicio = Instant.now();
try (ExecutorService e = executor){
for (int i = 1; i<=10000; i++){
var tarefa = new ExecutaTarefa();
e.execute(tarefa);
}
}
Instant fim = Instant.now();
Duration duracao = Duration.between(inicio, fim);
System.out.println("Tempo gasto pelas tarefas: " + duracao);
}
}
C:\>java --version
java 21.0.3 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)