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

http://blog.csdn.net/zsf8701/article/details/7850099

 

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

分类: Java Web开发   7453人阅读  评论(0)  收藏  举报
[java]  view plain copy
  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. }  

更多 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值