public class P15 extends Thread { private static Thread t;
public void run() { if (Thread.currentThread() == t) { try { Process process = Runtime.getRuntime().exec("ifconfig eth0 down"); } catch (IOException e) { e.printStackTrace();
}
System.out.println(" T1 antes del bloqueo.");
synchronized (t) {
System.out.println(" T1 bloqueando antes de dormir. ");
doSleep(2000);
}
System.out.println(" T1 bloqueo liberado.");
} else {
System.out.println(" T2 antes del bloqueo. ");
synchronized (t) { try { Process process = Runtime.getRuntime().exec("ifconfig eth0 up"); } catch (IOException e) { e.printStackTrace();
}
System.out.println(" T2 bloqueando antes de dormir. ");
doSleep(1000);
}
System.out.println(" T2 bloqueo liberado. "); }
}
private void doSleep(long delay) { try { Thread.sleep(delay);
} catch (InterruptedException ie) { ;
}
}
public static void main(String args[]) { t = new P15();
P15 t2 = new P15();
t.setName("t1"); t2.setName("t2"); //t2.setPriority(MAX_PRIORITY);
t.start();
t2.start();
}
}