From 00fd4f9634c1d3687f09e1947aeb4fe2a87fbe76 Mon Sep 17 00:00:00 2001 From: Anukalp Date: Thu, 12 Mar 2026 00:05:06 +0530 Subject: [PATCH] Fix the re-use of SecureRandom --- .../AlignedTimeseriesSessionExample.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/example/session/src/main/java/org/apache/iotdb/AlignedTimeseriesSessionExample.java b/example/session/src/main/java/org/apache/iotdb/AlignedTimeseriesSessionExample.java index 288bd65ddcb41..9b0e37e8b308a 100644 --- a/example/session/src/main/java/org/apache/iotdb/AlignedTimeseriesSessionExample.java +++ b/example/session/src/main/java/org/apache/iotdb/AlignedTimeseriesSessionExample.java @@ -340,6 +340,8 @@ private static void createTemplate() session.setSchemaTemplate("template1", "root.sg_1"); } + private static final SecureRandom Random = new SecureRandom(); + /** Method 1 for insert tablet with aligned timeseries */ private static void insertTabletWithAlignedTimeseriesMethod1() throws IoTDBConnectionException, StatementExecutionException { @@ -355,10 +357,8 @@ private static void insertTabletWithAlignedTimeseriesMethod1() for (long row = 1; row < 100; row++) { int rowIndex = tablet.getRowSize(); tablet.addTimestamp(rowIndex, timestamp); - tablet.addValue( - schemaList.get(0).getMeasurementName(), rowIndex, new SecureRandom().nextLong()); - tablet.addValue( - schemaList.get(1).getMeasurementName(), rowIndex, new SecureRandom().nextInt()); + tablet.addValue(schemaList.get(0).getMeasurementName(), rowIndex, Random.nextLong()); + tablet.addValue(schemaList.get(1).getMeasurementName(), rowIndex, Random.nextInt()); if (tablet.getRowSize() == tablet.getMaxRowNumber()) { session.insertAlignedTablet(tablet, true); @@ -390,9 +390,9 @@ private static void insertTabletWithAlignedTimeseriesMethod2() int row = tablet.getRowSize(); tablet.addTimestamp(row, time); - tablet.addValue(row, 0, new SecureRandom().nextLong()); + tablet.addValue(row, 0, Random.nextLong()); - tablet.addValue(row, 1, new SecureRandom().nextInt()); + tablet.addValue(row, 1, Random.nextInt()); if (tablet.getRowSize() == tablet.getMaxRowNumber()) { session.insertAlignedTablet(tablet, true); @@ -422,10 +422,10 @@ private static void insertNullableTabletWithAlignedTimeseries() int row = tablet.getRowSize(); tablet.addTimestamp(row, time); - tablet.addValue(row, 0, new SecureRandom().nextLong()); + tablet.addValue(row, 0, Random.nextLong()); if (time % 5 != 0) { - tablet.addValue(row, 1, new SecureRandom().nextInt()); + tablet.addValue(row, 1, Random.nextInt()); } if (tablet.getRowSize() == tablet.getMaxRowNumber()) { @@ -602,7 +602,7 @@ private static void insertTabletsWithAlignedTimeseries() tablet2.addTimestamp(row2, timestamp); tablet3.addTimestamp(row3, timestamp); for (int i = 0; i < 2; i++) { - long value = new SecureRandom().nextLong(); + long value = Random.nextLong(); tablet1.addValue(schemaList1.get(i).getMeasurementName(), row1, value); tablet2.addValue(schemaList2.get(i).getMeasurementName(), row2, value); tablet3.addValue(schemaList3.get(i).getMeasurementName(), row3, value); @@ -658,7 +658,7 @@ private static void insertTabletsWithAlignedTimeseriesWithNullValue() tablet2.addTimestamp(row2, timestamp); tablet3.addTimestamp(row3, timestamp); for (int i = 0; i < 2; i++) { - long value = new SecureRandom().nextLong(); + long value = Random.nextLong(); tablet1.addValue(schemaList1.get(i).getMeasurementName(), row1, value); tablet2.addValue(schemaList2.get(i).getMeasurementName(), row2, value); tablet3.addValue(schemaList3.get(i).getMeasurementName(), row3, value);