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

 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"
           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 how check the thread is running
  • check if a thread is running java
  • jlabel crossed text
  • java swing draw an image +portion
  • python read binary file
  • java check if thread is running

No comments yet.

Leave a Comment