另一方面,线程ID=进程ID+内部线程对象ID并不成立,
    参考: blog.csdn.net/heyetina/article/details/6633901
 
    如何在java代码中获取进程process id, 实现方法如下所示:
    参考: rednaxelafx.iteye.com/blog/716918

 

import java.lang.management.ManagementFactory;  
import java.lang.management.RuntimeMXBean;  
  
public class ShowOwnPID {  
    public static void main(String[] args) throws Exception {  
        int pid = getPid();  
        System.out.println("pid: " + pid);  
        System.in.read(); // block the program so that we can do some probing on it  
    }  
      
    private static int getPid() {  
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();  
        String name = runtime.getName(); // format: "pid@hostname"  
        try {  
            return Integer.parseInt(name.substring(0, name.indexOf('@')));  
        } catch (Exception e) {  
            return -1;  
        }  
    }  
}

 

 

 

 

 

 

 

 

http://www.cnblogs.com/mumuxinfei/p/3678854.html

 

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-02-13
  • 2022-12-23
猜你喜欢
  • 2022-12-30
  • 2022-01-01
  • 2022-12-23
  • 2021-11-14
  • 2021-07-13
  • 2022-12-23
  • 2022-02-10
相关资源
相似解决方案