Escolar Documentos
Profissional Documentos
Cultura Documentos
Taubat Unidade II
Curso de Cincia da
Computao
Programao Concorrente
Prof. Jorge Simeo
Nome: Juliano Almeida
RA:7083559163
Multiprogramao
Corresponde a diversos programas distintos ( paralelo ou
concorrente ) executando em um mesmo processador.
Processos e Threads
Processos : um programa em execuo, quais contem linhas de
{
Example e = new Example();
threadCalculate = new Thread(e);
threadListen = new Thread(e);
threadCalculate.start();
threadListen.start();
}
public void run()
{
Thread currentThread = Thread.currentThread();
if (currentThread == threadCalculate)
calculatePrimes();
else if (currentThread == threadListen)
listenForStop();
}
public void calculatePrimes()
{
int n = 1;
while (true)
{
n++;
boolean isPrime = true;
for (int i = 2; i < n; i++)
if ((n / i) * i == n)
{
isPrime = false;
break;
}
if (isPrime)
{
totalPrimesFound++;
System.out.println(n);
}
}
}
private void listenForStop()
{
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
String line = "";
while (!line.equals("stop"))
{
try
{
line = input.readLine();
}
catch (IOException exception) {}
}
System.out.println("Found " + totalPrimesFound +
" prime numbers before you said stop");
System.exit(1);
}
}
Referenciais
http://equipe.nce.ufrj.br/thome/grad/so_old/apostila/Processos.pdf
http://www.hardware.com.br/termos/thread
https://pt.wikipedia.org/wiki/Thread_(ci%C3%AAncia_da_computa
%C3%A7%C3%A3o)