ManagementUtils { public static int getCurrentProcessId() { int processId = -1; Object result = invoke(getProcessIdMethod, jvm); if (result instanceof Integer) { processId = (Integer) result; } else { String name = runtimeMXBean.getName(); String processIdValue = StringUtils.substringBefore(name, "@"); if (NumberUtils.isNumber(processIdValue)) { processId = Integer.parseInt(processIdValue); } } return processId; }  static int getCurrentProcessId();  }
@Test public void testGetCurrentProcessId() { int currentProcessId = ManagementUtils.getCurrentProcessId(); Assert.assertTrue(currentProcessId > 0); }