Click here to watch in Youtube :
https://www.youtube.com/watch?v=vhPpgr7HtKo&list=UUhwKlOVR041tngjerWxVccw
public class MyRunnable implements Runnable { public void run() { Thread t = Thread.currentThread(); // tests if this thread is alive System.out.println(t.getName()+" - isAlive = " + t.isAlive()); } }ThreadDemo.java
public class ThreadDemo { public static void main(String args[]) throws InterruptedException { Thread t = new Thread(new MyRunnable()); // this will call run() function t.start(); // waits for this thread to die t.join(); // tests if this thread is alive System.out.println(t.getName()+" - isAlive after join = " + t.isAlive()); } }Output
Thread-0 - isAlive = true Thread-0 - isAlive after join = falseClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_isAlive_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ThreadDemo_isAlive_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/4a03b5014bb513b61dfa414428ea9747b1421899/BasicJava/ThreadDemo_isAlive_App/?at=master
See also:
No comments:
Post a Comment