1
After executing the command gerenciador.start()
, my program does not return to the function main
, and does not print the message is over. It simply executes the command I have spoken. Does anyone know why this happens?
public class Principal
{
private static long startTime = System.currentTimeMillis();
public static void main(String[] args)
{
Fila sharedLine = new Fila();
Elevador elev = new Elevador(sharedLine);
Esquiador gerenciador = new Esquiador(sharedLine);
gerenciador.start();
//elev.start();
System.out.println("acabou");
long endTime = System.currentTimeMillis();
System.out.println("It took " + (int)(((endTime - startTime)/1000)/60) + " milliseconds");
}
}
public class Esquiador extends Thread
{
Fila sharedLine;
static boolean todosEntraram = false;
//String filaQuePertenco;
//int idEsquiador;
public Esquiador(Fila fila)
{
super("Esquiador");
sharedLine = fila;
//filaQuePertenco = filaQ;
//idEsquiador=id;
}
public void run()
{
for(int i = 0; i < 30; i++)
{
try
{
System.out.println("O esquiador está dormindo.");
Thread.sleep(500);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Esquiadores esquis = new Esquiadores(i);
//System.out.println("O esquiador "+ esquis.idEsquiador+ " entrou em seu 'run'");
//while(true)
//{
//política do esquiador para decidir em qual fila ele irá entrar
//printando o tamanho de cada fila.
System.out.println("O esquiador "+esquis.idEsquiador+" chegou para ingressar numa fila.");
System.out.println("Tamanho LS"+sharedLine.elementosLS.size());
System.out.println("Tamanho RS"+sharedLine.elementosRS.size());
System.out.println("Tamanho LT"+sharedLine.elementosLT.size());
System.out.println("Tamanho RT"+sharedLine.elementosRT.size());
System.out.println("Esquiador operando ...");
if(sharedLine.elementosLS.size()<2*sharedLine.elementosLT.size() && sharedLine.elementosLS.size()<2*sharedLine.elementosRT.size() && sharedLine.elementosLS.size()<sharedLine.elementosRS.size())
{
//this.filaQuePertenco = "LS";
//System.out.println("add ls");
sharedLine.adicionaFilaLS(esquis);
//printando elementos da fila LS
}
else if(sharedLine.elementosRS.size()<2*sharedLine.elementosLT.size() && sharedLine.elementosRS.size()<2*sharedLine.elementosRT.size() && sharedLine.elementosRS.size()<=sharedLine.elementosLS.size())
{
//this.filaQuePertenco = "RS";
//System.out.println("add rs");
sharedLine.adicionaFilaRS(esquis);
//printando elementos da fila RS
}
else if(sharedLine.elementosLT.size()<=sharedLine.elementosRT.size())
{
//this.filaQuePertenco = "LT";
//System.out.println("add lt");
sharedLine.adicionaFilaLT(esquis);
}
else
{
//this.filaQuePertenco = "RT";
//System.out.println("add rt");
sharedLine.adicionaFilaRT(esquis);
}
System.out.println("Situação das filas após a operação:");
System.out.println("Tamanho LS"+sharedLine.elementosLS.size());
System.out.println("Tamanho RS"+sharedLine.elementosRS.size());
System.out.println("Tamanho LT"+sharedLine.elementosLT.size());
System.out.println("Tamanho RT"+sharedLine.elementosRT.size());
//}
}
Esquiador.todosEntraram = true;
}
}
What is
gerenciador.start();
???– novic
There is a class that I created and put a run() method in it. This.start() manager I called after instantiating an object of the class I spoke, in order to create a thread and run the run method .
– Renan da Silva Alves
Put her in the question too! edit
– novic
All right, man. I’ve completed the main class and added the class I told you about.
– Renan da Silva Alves