fix: 修改pid函数
This commit is contained in:
parent
f25131c4b9
commit
2b58a59e6c
@ -132,7 +132,8 @@ public class RtkClusterService implements ApplicationRunner {
|
|||||||
if (sid != null) {
|
if (sid != null) {
|
||||||
RtkrcvSession upd = new RtkrcvSession();
|
RtkrcvSession upd = new RtkrcvSession();
|
||||||
upd.setSessionId(sid);
|
upd.setSessionId(sid);
|
||||||
upd.setPid((int) p.pid());
|
Integer pid = tryGetPidCompat(p);
|
||||||
|
if (pid != null) upd.setPid(pid);
|
||||||
upd.setStartTime(LocalDateTime.now());
|
upd.setStartTime(LocalDateTime.now());
|
||||||
upd.setUpdatedAt(LocalDateTime.now());
|
upd.setUpdatedAt(LocalDateTime.now());
|
||||||
sessionMapper.updateById(upd);
|
sessionMapper.updateById(upd);
|
||||||
@ -212,6 +213,18 @@ public class RtkClusterService implements ApplicationRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Java 8-only attempt to get Process pid; returns null if unavailable
|
||||||
|
private Integer tryGetPidCompat(Process p) {
|
||||||
|
try {
|
||||||
|
// Access private 'pid' field on UNIXProcess (Java 8)
|
||||||
|
java.lang.reflect.Field f = p.getClass().getDeclaredField("pid");
|
||||||
|
f.setAccessible(true);
|
||||||
|
Object v = f.get(p);
|
||||||
|
if (v instanceof Integer) return (Integer) v;
|
||||||
|
} catch (Exception ignore) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
static class DeviceEndpoint {
|
static class DeviceEndpoint {
|
||||||
private final String deviceId;
|
private final String deviceId;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user