Skip to content

Commit 6c66806

Browse files
committed
docs: add warning if there is to much created WriteApi instances
1 parent 4705392 commit 6c66806

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

client/src/main/java/com/influxdb/client/InfluxDBClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public interface InfluxDBClient extends AutoCloseable {
6767
/**
6868
* Create a new asynchronous non-blocking Write client.
6969
*
70+
* <p>
71+
* The {@link WriteApi} uses background thread to ingesting data into InfluxDB and is suppose to run as a singleton.
72+
* <b>Don't create new instance for every write.</b>
73+
* </p>
74+
*
7075
* @deprecated use {@link #makeWriteApi()}, the API is subject to removal in a next major release
7176
* @return the new client instance for the Write API
7277
*/

client/src/main/java/com/influxdb/client/internal/InfluxDBClientImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ public WriteApi makeWriteApi() {
129129

130130
@Nonnull
131131
@Override
132+
@SuppressWarnings("MagicNumber")
132133
public WriteApi makeWriteApi(@Nonnull final WriteOptions writeOptions) {
133134
Arguments.checkNotNull(writeOptions, "WriteOptions");
134135

136+
if (autoCloseables.size() >= 10) {
137+
String format = "There is already created %d instances of 'WriteApi'. "
138+
+ "The 'WriteApi' is suppose to run as a singleton and should be reused across threads. "
139+
+ "Use 'WriteApiBlocking` if you would like to use one-time ingesting.";
140+
LOG.warning(String.format(format, autoCloseables.size()));
141+
}
142+
135143
return new WriteApiImpl(writeOptions, retrofit.create(WriteService.class), options, autoCloseables);
136144
}
137145

0 commit comments

Comments
 (0)