另一方面,线程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; } } }