This is an automated email from the ASF dual-hosted git repository.
xingtanzjr pushed a commit to branch guonengtest
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/guonengtest by this push:
new 68068dec96 spotless
68068dec96 is described below
commit 68068dec962e030dd78b931848d3fdcabf8bed24
Author: Jinrui.Zhang <[email protected]>
AuthorDate: Mon Apr 17 23:19:36 2023 +0800
spotless
---
.../java/org/apache/iotdb/SessionPoolExample.java | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git
a/example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java
b/example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java
index f348a20ee8..3b3cc85d01 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java
+++ b/example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java
@@ -34,7 +34,6 @@ import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
public class SessionPoolExample {
@@ -56,8 +55,6 @@ public class SessionPoolExample {
private static AtomicInteger totalRowNumber = new AtomicInteger();
- private static AtomicLong insertTime = new AtomicLong();
-
private static Random r;
/** Build a custom SessionPool for this example */
@@ -84,11 +81,17 @@ public class SessionPoolExample {
protected CountDownLatch latch;
protected long currentTimestamp;
+ protected int count;
+
+ protected SyncWriteSignal(int count) {
+ this.count = count;
+ }
+
protected void syncCountDownBeforeInsert() {
if (needResetLatch) {
synchronized (this) {
if (needResetLatch) {
- latch = new CountDownLatch(THREAD_NUMBER);
+ latch = new CountDownLatch(this.count);
needResetLatch = false;
currentTimestamp = System.currentTimeMillis();
}
@@ -128,7 +131,7 @@ public class SessionPoolExample {
for (int j = 0; j < TOTAL_BATCH_COUNT_PER_DEVICE; j++) {
signal.syncCountDownBeforeInsert();
try {
- int insertDeviceCount = insertRecords(index);
+ int insertDeviceCount = insertRecords(index,
signal.currentTimestamp);
totalRowNumber.addAndGet(insertDeviceCount);
signal.finishInsert();
signal.waitCurrentLoopFinished();
@@ -152,7 +155,7 @@ public class SessionPoolExample {
Thread[] threads = new Thread[THREAD_NUMBER];
- SyncWriteSignal signal = new SyncWriteSignal();
+ SyncWriteSignal signal = new SyncWriteSignal(THREAD_NUMBER);
for (int i = 0; i < THREAD_NUMBER; i++) {
threads[i] = new Thread(new InsertWorker(signal, i));
}
@@ -213,9 +216,8 @@ public class SessionPoolExample {
}
// more insert example, see SessionExample.java
- private static int insertRecords(int threadIndex)
+ private static int insertRecords(int threadIndex, long timestamp)
throws StatementExecutionException, IoTDBConnectionException {
- long time = insertTime.get();
List<String> deviceIds = new ArrayList<>();
List<Long> times = new ArrayList<>();
List<List<String>> measurementsList = new ArrayList<>();
@@ -225,7 +227,7 @@ public class SessionPoolExample {
for (int j = threadIndex; j < DEVICE_NUMBER; j += THREAD_NUMBER) {
String deviceId = "root.test.g_0.d_" + j;
deviceIds.add(deviceId);
- times.add(time);
+ times.add(timestamp);
List<Object> values = new ArrayList<>();
for (int i = 0; i < SENSOR_NUMBER; i++) {
values.add(r.nextFloat());