Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Check if the thread is started and is running

Java: Check if the thread is started and is running
{filelink=10863}

 public class ThreadLive extends Thread
 	{  
       public void run()
      {  
           for ( int i = 0; i < 10; i++ )
           	{  
           Thread thr = Thread.currentThread();
           String thr_name = thr.getName();
           System.out.println("Thread: " + thr_name);  
           }  
       }
       public static void main(String[] argv)
       	 {
           // Create a thread
           ThreadLive myThr = new ThreadLive();
           // change the thread name
           myThr.setName("My Thread");     
           /* show the different states of the thread */
          System.out.println("Before calling the 'start ()' method, myThr.isAlive()=" +
 							  myThr.isAlive());  // "false"
           myThr.start();  
           System.out.println("After calling the start () method, myThr.isAlive()=" +
 								myThr.isAlive()); // "true"
           System.out.println("at the end of the program, myThr.isAlive()="
           	                   + myThr.isAlive());  //true
       }  
 }

Users who found this page were searching for:

  • java check if thread is running
  • check if a thread is running java
  • python read binary file
  • java how check the thread is running
  • java swing draw an image +portion
  • jlabel crossed text

No comments yet.

Leave a Comment