ThreadGroup class isDestroyed () método : Aquí, vamos a aprender sobre el método isDestroyed () de ThreadGroup Class con su sintaxis y su ejemplo.
método ThreadGroup Class isDestroyed ()
- isDestroyed () método está disponible en java.lang Class.
- isDestroyed () se utiliza para comprobar si este grupo de hilos ha sido destruido o no destruidas.
método
método
isDestroyed ()
es un método no package, es accesible con el único objeto static y si tratamos de acceder al método con el nombre class entonces obtendrá un error.
método isDestroyed ()
no class una excepción en el momento de comprobar el comportamiento destruido de este grupo de hilos.
Sintaxis:
public final boolean isDaemon();
Parámetro (s):
No acepta cualquier parámetro.
throw valor:
El tipo Return de este método es
return
– devuelve cierto cuando este grupo de hilos ha sido destruido lo contrario, devuelve falso.
Ejemplo:
// Java program to demonstrate the example
// of boolean isDaemon()method of ThreadGroup
public class Daemon implements Runnable {
public static void main(String[] args) {
Daemon damn = new Daemon();
damn.isDaemn();
}
public void isDaemn() {
try {
// Create two thread group and the named are base
// and derived
ThreadGroup base = new ThreadGroup("Base ThreadGroup");
ThreadGroup derived = new ThreadGroup(base, "Derived ThreadGroup");
// create two threads
Thread th1 = new Thread(base, this);
Thread th2 = new Thread(derived, this);
// By using getName() method is to retrieve the
// name of the thread th1
System.out.println(th1.getName() + " " + "begins.....");
// By using start() method is to start its execution
// of thread th1
th1.start();
// By using getName() method is to retrieve the
// name of the thread th2
System.out.println(th2.getName() + " " + "begins.....");
// By using start() method is to start its execution
// of thread th2
th2.start();
System.out.println();
// By using isDaemon() method is to check the
// daemon status of the thread group
boolean b1 = base.isDaemon();
boolean b2 = derived.isDaemon();
System.out.println("Is" + " " + base.getName() + " " + "daemon threadgroup:" + " " + b1);
System.out.println("Is" + " " + derived.getName() + " " + "daemon threadgroup:" + " " + b2);
// By using join() method is to wait the current
// thread till complete execution of another
// thread
th1.join();
th2.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
// Override run()
public void run() {
for (int k = 0; k < 100; ++k)
++k;
System.out.println(Thread.currentThread().getName() + " " + "ends.....");
}
}
salida
Thread-0 begins.....
Thread-0 ends.....
Thread-1 begins.....
Thread-1 ends.....
Is Base ThreadGroup daemon threadgroup: false
Is Derived ThreadGroup daemon threadgroup: false