dosubot[bot] commented on issue #2667:
URL:
https://github.com/apache/incubator-hugegraph/issues/2667#issuecomment-2380587752
<!-- Answer -->
To ensure `removeSelfServerInfo` is executed when the server is killed
suddenly, you should handle the server shutdown gracefully by ensuring that the
`close` method is called. The `close` method in `ServerInfoManager` already
calls `removeSelfServerInfo` if the `dbExecutor` is not shut down.
Here is the relevant part of the `close` method:
```java
public synchronized boolean close() {
this.closed = true;
if (!this.dbExecutor.isShutdown()) {
this.removeSelfServerInfo();
this.call(() -> {
try {
this.tx().close();
} catch (ConnectionException ignored) {
// ConnectionException means no connection established
}
this.graph.closeTx();
return null;
});
}
return true;
}
```
To handle sudden server termination, you can use a shutdown hook in your
application to ensure that the `close` method is called:
```java
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
serverInfoManager.close();
} catch (Exception e) {
e.printStackTrace();
}
}));
```
This shutdown hook will be executed when the JVM is shutting down, ensuring
that `removeSelfServerInfo` is called to remove the ServerInfo
<sup>[[1]](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]