Java如何检测当前进程的状态呢?
实现思路:
       1.使用Thread.currentThread()获取当前进程
  2.使用isAlive()获取进程的状态
例:
public class testThreadAlive extends Thread {
   public void run() {
      for (int i = 0; i < 4; i++) {
         printMsg();
      }
   }
   public void printMsg() {
      Thread t = Thread.currentThread();
      String name = t.getName();
      System.out.println("进程名称:" + name);
   }
   public static void main(String[] args) {
      testThreadAlive t= new testThreadAlive();
      t.setName("MyThread");
      System.out.println(t.isAlive());
      t.start();     
      System.out.println(t.isAlive());
   }
}									
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

			
               
               
               
               
          
