jfcmacro icon

Ejemplo de suicidio de hilo

jfcmacro | PRO | 03/28/19 08:29:51 PM UTC | 0 ⭐ | 433 👁️ | Never ⏰ | []
Java |

450 B

|

None

|

0 👍

/

0 👎

class HiloSeppuku implements Runnable {
 
    public void run() {
    Thread t = Thread.currentThread();
 
    while(true) {
        System.out.println("Hilo: " + t);
        if (t.isInterrupted()) break; // Seppuku done!
    }
    }
 
    public static void main(String args[]) {
    Thread t = new Thread(new HiloSeppuku());
 
    t.start();
 
    try {
        Thread.sleep(4000);
        t.interrupt();
        Thread.sleep(3000);
        t.join();
    }
    catch (InterruptedException ie) {
    }
    }
}

Comments