influxdata / influxdata/influxdb-java
InfluxDB Client prevents application from exiting when batch mode is enabled
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 1.2k
- Forks
- 469
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi Team,
When an influxdb-java client is created and batch is enabled, it prevents the application from exiting normally due to the use of a default non-daemon thread pool. This prevents the application from shutting down in the event that the main thread exits/ crashes. Adding a shutdown hook would not help with closing the client as the JVM will only run shutdown hooks after all non-daemon thread exits. A small example would be running the following:
```java
public class App {
public static void main(String[] args) {
InfluxDB influxDB = InfluxDBFactory.connect("http://localhost:8086");
influxDB.enableBatch();
Runtime.getRuntime().addShutdownHook(new Thread(influxDB::close));
System.out.println(influxDB.ping());
}
}
```
Currently, the workaround is to explicitly specify a daemon thread factory:
```java
influxDB.enableBatch(
BatchOptions.DEFAULTS
.threadFactory(runnable -> {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
return thread;
})
);
```
But I was wondering if it would be a better user experience to have this be the default behaviour so that the main application is allowed to exit normally. The rationale is that a common use case for influxdb-java is to write application metrics and usually one would not expect a metrics library to affect the main application (e.g. cause it to not exit properly).
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne am enableBatch-Einstiegspunkt und an der im Bericht gezeigten BatchOptions.DEFAULTS-Konfiguration und reproduziere dann den Lebenszyklus mit dem bereitgestellten App-Beispiel. Verfolge, wie die Standard-Thread-Factory erstellt wird, und überprüfe, dass die Anwendung normal beendet werden kann, wenn der Batch-Modus aktiviert ist, während das Batch-Verhalten erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100