public class LiebreThread implements Runnable{
public LiebreThread(){
}
@Override
public void run() {
// TODO Auto-generated method stub
int i=0;
System.out.println("arranco la liebre");
while(i<5){
try{
Thread.sleep(2000);
System.out.println("soy la liebre");
}catch(InterruptedException ex){
}
i++;
}
System.out.println("termina la liebre");
}
}
------------------------------------------------------------------------------------------------------------
public class TortugaThread implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
int i=0;
System.out.println("arranco la tortuga");
while(i<5){
try{
Thread.sleep(5000);
System.out.println("soy la tortuga");
}catch(InterruptedException ex){
}
i++;
}
System.out.println("termina la tortuga");
}
}
------------------------------------------------------------------------------------------------------------
public class Main {
public static void main (String args[]){
Thread tortuga1 = new Thread(new TortugaThread()); //creación del proceso tortuga1
Thread liebre1 = new Thread(new LiebreThread()); //creación del proceso liebre1
tortuga1.start();
//si quisiera asignarle más prioridad tortuga1.setPriority(Thread.MAX_PRIORITY);
liebre1.start();
//si quisiera asignarle menos prioridad liebre1.setPriority(Thread.MIN_PRIORITY);
}
}
+10 prro
ResponderEliminar