From 83e4c563d9de52f4f3467898e93c52cff32122a4 Mon Sep 17 00:00:00 2001 From: sheyanjie-qq <249478495@qq.com> Date: Mon, 24 Mar 2025 14:05:58 +0800 Subject: [PATCH] improve comments --- .../java/com/taos/example/highvolume/ConsumerTask.java | 9 ++++----- .../com/taos/example/highvolume/CreateSubTableTask.java | 2 -- .../com/taos/example/highvolume/FastWriteExample.java | 9 ++++----- .../java/com/taos/example/highvolume/MockDataSource.java | 2 +- .../java/com/taos/example/highvolume/ProducerTask.java | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ConsumerTask.java b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ConsumerTask.java index c29ae6fdea..dc1eecfc7d 100644 --- a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ConsumerTask.java +++ b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ConsumerTask.java @@ -76,9 +76,9 @@ class ConsumerTask implements Runnable, Stoppable { long lastTimePolled = System.currentTimeMillis(); while (active) { ConsumerRecords records = consumer.poll(Duration.ofMillis(100)); - for (ConsumerRecord record : records) { + for (ConsumerRecord metersRecord : records) { i++; - Meters meters = Meters.fromString(record.value()); + Meters meters = Meters.fromString(metersRecord.value()); pstmt.setString(1, meters.getTableName()); pstmt.setTimestamp(2, meters.getTs()); pstmt.setFloat(3, meters.getCurrent()); @@ -90,8 +90,8 @@ class ConsumerTask implements Runnable, Stoppable { pstmt.executeBatch(); } if (i % (10L * batchSizeByRow) == 0){ - //pstmt.executeUpdate(); - consumer.commitAsync(); + pstmt.executeUpdate(); + consumer.commitSync(); } } @@ -107,7 +107,6 @@ class ConsumerTask implements Runnable, Stoppable { } catch (Exception e) { logger.error("Consumer Task {} Error", taskId, e); } finally { - // 关闭消费者 consumer.close(); } } diff --git a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/CreateSubTableTask.java b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/CreateSubTableTask.java index 5c10483283..309d0b45a8 100644 --- a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/CreateSubTableTask.java +++ b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/CreateSubTableTask.java @@ -14,8 +14,6 @@ class CreateSubTableTask implements Runnable { private final int subTableEndIndex; private final String dbName; - - public CreateSubTableTask(int taskId, int subTableStartIndex, int subTableEndIndex, diff --git a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/FastWriteExample.java b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/FastWriteExample.java index 892537c499..ce9be23ce9 100644 --- a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/FastWriteExample.java +++ b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/FastWriteExample.java @@ -14,13 +14,12 @@ import java.util.concurrent.atomic.AtomicInteger; public class FastWriteExample { - final static Logger logger = LoggerFactory.getLogger(FastWriteExample.class); - final static DataBaseMonitor databaseMonitor = new DataBaseMonitor(); + static final Logger logger = LoggerFactory.getLogger(FastWriteExample.class); + static final DataBaseMonitor databaseMonitor = new DataBaseMonitor(); static ThreadPoolExecutor writerThreads; static ThreadPoolExecutor producerThreads; - final static ThreadPoolExecutor statThread = (ThreadPoolExecutor) Executors.newFixedThreadPool(1); - - private final static List allTasks = new ArrayList<>(); + static final ThreadPoolExecutor statThread = (ThreadPoolExecutor) Executors.newFixedThreadPool(1); + static private final List allTasks = new ArrayList<>(); private static int readThreadCount = 5; private static int writeThreadPerReadThread = 5; diff --git a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/MockDataSource.java b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/MockDataSource.java index aa74912c34..9b05fead79 100644 --- a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/MockDataSource.java +++ b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/MockDataSource.java @@ -33,7 +33,7 @@ class MockDataSource implements Iterator { @Override public Meters next() { - // use interlace rows one to simulate the data distribution in real world + // use interlace rows to simulate the data distribution in real world if (index % (tableEndIndex - tableStartIndex + 1) == 0) { currentMs += 1000; } diff --git a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ProducerTask.java b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ProducerTask.java index 6c217df8ab..76dbaaf6c0 100644 --- a/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ProducerTask.java +++ b/docs/examples/JDBC/highvolume/src/main/java/com/taos/example/highvolume/ProducerTask.java @@ -49,8 +49,8 @@ class ProducerTask implements Runnable, Stoppable { // to avoid the data of the sub-table out of order. we use the partition key to ensure the data of the same sub-table is sent to the same partition. // Because efficient writing use String hashcode,here we use another hash algorithm to calculate the partition key. long hashCode = Math.abs(ReqId.murmurHash32(key.getBytes(), 0)); - ProducerRecord record = new ProducerRecord<>(Util.getKafkaTopic(), (int)(hashCode % Util.getPartitionCount()), key, value); - producer.send(record); + ProducerRecord metersRecord = new ProducerRecord<>(Util.getKafkaTopic(), (int)(hashCode % Util.getPartitionCount()), key, value); + producer.send(metersRecord); } } catch (Exception e) { logger.error("task id {}, send message error: ", taskId, e);