/** * 獲取當前線程id */ private Long getThreadId() { try { return Thread.currentThread().getId(); } catch (Exception e) { return null; } } /** * 獲取當前進程id */ private Long getProcessId() { try { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); String pid = name.substring(0, name.indexOf('@' )); return Long.parseLong(pid); } catch (Exception e) { return null; } } /** * 獲取當前服務器ip地址 */ private String getServerIp() { try { //用 getLocalHost() 方法創建的InetAddress的對象 InetAddress address = InetAddress.getLocalHost(); return address.getHostAddress(); } catch (Exception e) { return null; } }