Skip to content

Commit 577142f

Browse files
committed
docs: fix durable-example based on feedback.
1 parent 1a5aa70 commit 577142f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

examples/src/main/java/com/influxdb/v3/durable/DurableExample.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ public static void main(final String[] args) {
125125

126126
// borrow then return a client
127127
InfluxDBClient client = clientPool.borrowClient();
128-
logger.info(" [writeTaskPointsOK " + count + "] Writing " + points.size()
129-
+ " points with client " + client.hashCode());
130-
client.writePoints(points);
131-
clientPool.returnClient(client);
128+
try {
129+
logger.info(" [writeTaskPointsOK " + count + "] Writing " + points.size()
130+
+ " points with client " + client.hashCode());
131+
client.writePoints(points);
132+
} catch (Exception e) {
133+
logger.severe(" [writeTaskPointsOK " + count + "] Unexpected Error writing points "
134+
+ e.getMessage());
135+
} finally {
136+
clientPool.returnClient(client);
137+
}
132138

133139
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
134140
count++;

examples/src/main/java/com/influxdb/v3/durable/InfluxClientPool.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public synchronized InfluxDBClient borrowClient() {
8181
client = InfluxDBClient.getInstance(clientConfig);
8282
runners.add(client);
8383
if (activeCount() >= maxSize) {
84+
// N.B. this is just an example implementation.
85+
// For simplicity this _example_ will allow the maxSize value to be exceeded with a severe warning.
86+
// In a production environment maxSize should be managed appropriately.
8487
logger.severe("Max pool size " + maxSize + " exceeded: " + "actives "
8588
+ activeCount() + " idles " + idleCount()
8689
+ " (hint: Is there a process hogging zombie clients?)");
@@ -152,11 +155,11 @@ public synchronized void close() throws Exception {
152155
}
153156
}
154157

155-
public int activeCount() {
158+
public synchronized int activeCount() {
156159
return runners.size();
157160
}
158161

159-
public int idleCount() {
162+
public synchronized int idleCount() {
160163
return idlers.size();
161164
}
162165
}

0 commit comments

Comments
 (0)