You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// [2020-03-22T20:50:12.929Z, between 6 and 9 feet, coyote_creek, 8.12]
46
55
// ]]], error=null]], error=null]
47
-
48
-
influxDB.close(); // (8)
49
56
```
50
57
51
58
### Connecting to InfluxDB
@@ -137,13 +144,26 @@ With batching enabled the client provides two strategies how to deal with errors
137
144
When new data points are written before the previous (failed) points are successfully written, those are queued inside the client and wait until older data points are successfully written.
138
145
Size of this queue is limited and configured by `BatchOptions.bufferLimit` property. When the limit is reached, the oldest points in the queue are dropped. 'Retry on error' strategy is used when individual write batch size defined by `BatchOptions.actions` is lower than `BatchOptions.bufferLimit`.
139
146
140
-
Note:
147
+
#### Ensure application exit when batching is enabled
148
+
`BatchOptions.DEFAULTS` creates a non-daemon thread pool which prevents the JVM from initiating shutdown in the case of
149
+
exceptions or successful completion of the main thread. This will prevent shutdown hooks (many frameworks and plain JVM
150
+
applications use these to close/ cleanup resources) from running, preventing graceful termination of the application.
151
+
152
+
Thus, configuring batch options with a daemon thread pool will solve this issue and will for example ensure that the registered
153
+
(5) shutdown hook is run to close the `InfluxDB` client properly (flushing and closing of resources will happen).
154
+
155
+
### Close InfluxDB Client on JVM Termination
156
+
(5) In order to ensure that in-flight points are flushed and resources are released properly, it is essential to call
157
+
`influxDB.close()` the client when it is no longer required.
158
+
159
+
Registering a shutdown hook is a good way to ensure that this is done on application termination regardless of exceptions
160
+
that are thrown in the main thread of the code. Note that if you are using a framework, do check the documentation for its
161
+
way of configuring shutdown lifecycle hooks or if it might already be calling `close` automatically.
141
162
142
-
* Batching functionality creates an internal thread pool that needs to be shutdown explicitly as part of a graceful application shutdown or the application will terminate properly. To do so, call `influxDB.close()`.
0 commit comments