Skip to content

Instantly share code, notes, and snippets.

@alexjosesilva
Created February 22, 2024 18:53
Show Gist options
  • Save alexjosesilva/37e029cc4cff49a15ea0f7cb20a5b667 to your computer and use it in GitHub Desktop.
Save alexjosesilva/37e029cc4cff49a15ea0f7cb20a5b667 to your computer and use it in GitHub Desktop.
Programacao Concorrente Paralela
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ProgramaConcorrenteParalela {
public static void main(String[] args) {
// Cria um pool de threads com 5 threads
ExecutorService executor = Executors.newFixedThreadPool(5);
// Submete tarefas para execução
for (int i = 0; i < 10; i++) {
int taskNumber = i;
executor.submit(() -> {
System.out.println("Tarefa " + taskNumber + " executada por thread: " + Thread.currentThread().getName());
});
}
// Finaliza o executor após a conclusão das tarefas
executor.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment