Saturday, 10 June 2017

Java Tutorial: Java Threads (How to get the Thread state) ~ foundjava


Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial: Java Threads (How to get the Thread state) 
MyRunnable.java
public class MyRunnable implements Runnable
{
    public void run()
    {
        /*
         * Returns the state of this thread.
         */
        Thread.State state = Thread.currentThread().getState();
        System.out.print("Thread Name = " + Thread.currentThread().getName());
        System.out.println(" , state = " + state);
    }
}
ThreadDemo.java
public class ThreadDemo
{

    public static void main(String args[])
    {
        Thread t = new Thread(new MyRunnable());
        // this will call run() function
        t.start();
    }
}
Output
Thread Name = Thread-0 , state = RUNNABLE

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment