Skip to content

Commit e570cd9

Browse files
committed
fix: avoid load strings to array list multiple times
1 parent 418c6de commit e570cd9

File tree

1 file changed

+6
-4
lines changed
  • hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node

1 file changed

+6
-4
lines changed

hugegraph-cluster-test/hugegraph-clustertest-minicluster/src/main/java/org/apache/hugegraph/ct/node/ServerNodeWrapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@
4343
import java.nio.file.Paths;
4444
import java.util.ArrayList;
4545
import java.util.Arrays;
46+
import java.util.Collections;
4647
import java.util.List;
4748

4849
public class ServerNodeWrapper extends AbstractNodeWrapper {
4950

50-
private static List<String> hgJars = new ArrayList<>();
51+
private static List<String> hgJars = loadHgJarsOnce();
5152
public ServerNodeWrapper(int clusterIndex, int index) {
5253
super(clusterIndex, index);
5354
this.fileNames = new ArrayList<>(
@@ -59,7 +60,6 @@ public ServerNodeWrapper(int clusterIndex, int index) {
5960
this.startLine = "INFO: [HttpServer] Started.";
6061
createNodeDir(Paths.get(SERVER_PACKAGE_PATH), getNodePath());
6162
createLogDir();
62-
loadHgJars();
6363
}
6464

6565
private static void addJarsToClasspath(File directory, List<String> classpath) {
@@ -91,16 +91,18 @@ private static void addOrderedJarsToClasspath(File directory, List<String> class
9191
}
9292
}
9393

94-
private void loadHgJars(){
94+
private static List<String> loadHgJarsOnce(){
95+
ArrayList<String> jars = new ArrayList<>();
9596
try (InputStream is = ServerNodeWrapper.class.getResourceAsStream("/jar.txt");
9697
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
9798
String line;
9899
while ((line = reader.readLine()) != null) {
99-
hgJars.add(line);
100+
jars.add(line);
100101
}
101102
} catch (IOException e) {
102103
e.printStackTrace();
103104
}
105+
return Collections.unmodifiableList(jars);
104106
}
105107

106108
@Override

0 commit comments

Comments
 (0)