jfcmacro

EjemploHilo7.java

Mar 27th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. class EjemploHilo7 implements Runnable {
  2.  
  3.     public EjemploHilo7() {
  4.     }
  5.  
  6.     public void run() {
  7.     Thread t = Thread.currentThread();
  8.  
  9.     while (true) {
  10.         System.out.println("Esto es otro hilo: " + t);
  11.         if (t.isInterrupted()) break;
  12.     }
  13.     System.out.println("Good bye, cruel world!");
  14.     }
  15.  
  16.     public static void main(String []args) {
  17.     ThreadGroup tg = new ThreadGroup("fumador");
  18.     Thread eh7_1 = new Thread(tg, new EjemploHilo7(), "Ejemplo hilo 7 1");
  19.  
  20.     eh7_1.start();
  21.     try {
  22.  
  23.         Thread.currentThread().sleep(2000);
  24.         eh7_1.interrupt();
  25.  
  26.     }
  27.     catch (InterruptedException ie) {
  28.     }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment