-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (29 loc) · 958 Bytes
/
Copy pathMain.java
File metadata and controls
33 lines (29 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Função principal que executa a busca de números primos em paralelo.
*
* @author Isabela Bella Bortoleto
* @version 1.2
*/
public class Main {
public static void main(String[] args) {
int limite = 100_000;
int passo = 1000;
Thread[] threads = new Thread[limite / passo];
for (int i = 0; i < threads.length; i++) {
int inicio = i * passo;
int fim = Math.min(inicio + passo, limite);
BuscaPrimos buscaPrimos = new BuscaPrimos(inicio, fim);
threads[i] = new Thread(buscaPrimos);
threads[i].start();
}
// Aguarda todas as threads terminarem
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException("Thread foi interrompida", e);
}
}
System.out.println("Busca de primos concluída.");
}
}