Java 获取当前线程的相关信息

  1. public class iphxer  
  2. {  
  3.     @SuppressWarnings("static-access")  
  4.     public static void main (String s[])  
  5.     {  
  6.         System.out.println("iphxer");  
  7.         new Thread(new B("iphxer0")).start();  
  8.         new Thread(new B("iphxer1")).start();  
  9.         new Thread(new B("iphxer2")).start();  
  10.         new Thread(new B("iphxer3")).start();  
  11.         try  
  12.         {  
  13.             Thread.sleep(5000);  
  14.         }  
  15.         catch(InterruptedException e)  
  16.         {  
  17.             e.printStackTrace();  
  18.         }  
  19.         Thread current = Thread.currentThread();  
  20.         System.out.println(current.getPriority());  
  21.         System.out.println(current.getName());  
  22.         System.out.println(current.activeCount());  
  23.         System.out.println(current.getId());  
  24.         System.out.println(current.getThreadGroup());  
  25.         System.out.println(current.getStackTrace());  
  26.         System.out.println(current.hashCode());  
  27.         System.out.println(current.toString());  
  28.     }  
  29. }  
  30.   
  31. class B implements Runnable  
  32. {  
  33.     private int num=0;  
  34.     private String name;  
  35.     public B(String s)  
  36.     {  
  37.         this.name = s;  
  38.     }  
  39.     public void run()  
  40.     {  
  41.         System.out.println(this.name);  
  42.         try  
  43.         {  
  44.             Thread.sleep(1000);  
  45.         }  
  46.         catch (InterruptedException e)  
  47.         {  
  48.             e.printStackTrace();  
  49.         }  
  50.     }  
  51. }  

 

posted @ 2016-12-08 08:51  天涯海角路  阅读(112)  评论(0)    收藏  举报