Created
February 22, 2024 18:53
-
-
Save alexjosesilva/37e029cc4cff49a15ea0f7cb20a5b667 to your computer and use it in GitHub Desktop.
Programacao Concorrente Paralela
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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