Click here to watch in Youtube :
Click the below Image to Enlarge
![]() |
| Java Tutorial: Java Threads (How to get the Thread state) |
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);
}
}
public class ThreadDemo
{
public static void main(String args[])
{
Thread t = new Thread(new MyRunnable());
// this will call run() function
t.start();
}
}
Thread Name = Thread-0 , state = RUNNABLE
Click the below link to download the code:

No comments:
Post a Comment