diff --git a/README.md b/README.md index 20085b2..991a9c7 100644 --- a/README.md +++ b/README.md @@ -107,9 +107,11 @@ To use TDLight Java you need to include one or more native dependencies: - `tdlight-natives-osx-amd64` ## Usage - An example on how to use TDLight Java can be found here: [Example.java](https://github.com/tdlight-team/tdlight-java/blob/master/example/src/main/java/it.tdlight.example/Example.java) +### Advanced usage +If you want to disable the automatic runtime shutdown hook, you should set the property `it.tdlight.enableShutdownHooks` to `false` + ### TDLight methods documentation [TdApi JavaDoc](https://tdlight-team.github.io/tdlight-docs) diff --git a/src/main/java/it/tdlight/common/internal/InternalClient.java b/src/main/java/it/tdlight/common/internal/InternalClient.java index eb1f0c1..f709f53 100644 --- a/src/main/java/it/tdlight/common/internal/InternalClient.java +++ b/src/main/java/it/tdlight/common/internal/InternalClient.java @@ -191,11 +191,13 @@ public final class InternalClient implements ClientEventsHandler, TelegramClient } private void onJVMShutdown() { - try { - logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId); - this.send(new TdApi.Close(), result -> {}, ex -> {}); - } catch (Throwable ex) { - logger.debug("Failed to send shutdown request to session {}", clientId); + if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) { + try { + logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId); + this.send(new TdApi.Close(), result -> {}, ex -> {}); + } catch (Throwable ex) { + logger.debug("Failed to send shutdown request to session {}", clientId); + } } } diff --git a/src/main/java/it/tdlight/common/internal/InternalReactiveClient.java b/src/main/java/it/tdlight/common/internal/InternalReactiveClient.java index 079d533..3002e21 100644 --- a/src/main/java/it/tdlight/common/internal/InternalReactiveClient.java +++ b/src/main/java/it/tdlight/common/internal/InternalReactiveClient.java @@ -310,11 +310,13 @@ public final class InternalReactiveClient implements ClientEventsHandler, Reacti } private void onJVMShutdown() { - try { - logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId); - sendCloseAndIgnoreResponse(); - } catch (Throwable ex) { - logger.debug("Failed to send shutdown request to session {}", clientId); + if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) { + try { + logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId); + sendCloseAndIgnoreResponse(); + } catch (Throwable ex) { + logger.debug("Failed to send shutdown request to session {}", clientId); + } } }