jfcmacro

EjemploHilo6.java

Mar 27th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. class EjemploHilo6 implements Runnable {
  2.  
  3.     private int priority;
  4.  
  5.     public EjemploHilo6(int priority) {
  6.     this.priority = priority;
  7.     }
  8.    
  9.     public void run() {
  10.     Thread t = Thread.currentThread();
  11.     t.setPriority(priority);
  12.     for (int i = 0; i < 20; ++i) {
  13.         System.out.println("Esto es otro hilo: " + t);
  14.     }
  15.     }
  16.  
  17.     public static void main(String []args) {
  18.     ThreadGroup tg = new ThreadGroup("fumador");
  19.     Thread eh6_1 = new Thread(tg, new EjemploHilo6(1), "Ejemplo hilo 6 1");
  20.     Thread eh6_2 = new Thread(tg, new EjemploHilo6(10), "Ejemplo hilo 6 2");
  21.  
  22.     eh6_1.start();
  23.     eh6_2.start();
  24.     try {
  25.  
  26.         eh6_1.join();
  27.         eh6_2.join();
  28.     }
  29.     catch (InterruptedException ie) {
  30.     }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment