jfcmacro

EjemploHilo5.java

Mar 27th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. class EjemploHilo5 implements Runnable {
  2.  
  3.     public void run() {
  4.     System.out.println("Esto es otro hilo: " + Thread.currentThread());
  5.     }
  6.  
  7.     public static void main(String []args) {
  8.     ThreadGroup tg = new ThreadGroup("fumador");
  9.     Thread eh3_1 = new Thread(tg, new EjemploHilo5(), "Ejemplo hilo 3 1");
  10.     Thread eh3_2 = new Thread(tg, new EjemploHilo5(), "Ejemplo hilo 3 2");
  11.  
  12.     eh3_1.start();
  13.     eh3_2.start();
  14.     try {
  15.         System.out.println("Activos: " + tg.activeCount());
  16.         System.out.println("Esta vivo: " + eh3_1.isAlive());
  17.         System.out.println("Estos un hilo " + Thread.currentThread());
  18.         eh3_1.join();
  19.         System.out.println("Esta vivo: " + eh3_1.isAlive());
  20.         tg.list();
  21.         System.out.println("Activos: " + tg.activeCount());
  22.     }
  23.     catch (InterruptedException ie) {
  24.     }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment