You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/07/16 05:27:48 UTC
[iotdb] branch master updated: Optimize the implementation of
singleton (#3585)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 56ea509 Optimize the implementation of singleton (#3585)
56ea509 is described below
commit 56ea509d863a54ff7a9f77a6972ec23e5df3d7dd
Author: limeng <li...@live.cn>
AuthorDate: Fri Jul 16 13:27:19 2021 +0800
Optimize the implementation of singleton (#3585)
Co-authored-by: limeng32 <li...@yonyou.com>
---
.../java/org/apache/iotdb/db/rescon/TVListAllocator.java | 12 ++++++++----
.../main/java/org/apache/iotdb/db/service/UpgradeSevice.java | 9 +++++++--
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java b/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
index b90c33e..f2e54ab 100644
--- a/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
+++ b/server/src/main/java/org/apache/iotdb/db/rescon/TVListAllocator.java
@@ -40,10 +40,14 @@ public class TVListAllocator implements TVListAllocatorMBean, IService {
String.format(
"%s:%s=%s", IoTDBConstant.IOTDB_PACKAGE, IoTDBConstant.JMX_TYPE, getID().getJmxName());
- private static final TVListAllocator INSTANCE = new TVListAllocator();
-
public static TVListAllocator getInstance() {
- return INSTANCE;
+ return InstanceHolder.INSTANCE;
+ }
+
+ private static class InstanceHolder {
+ private static final TVListAllocator INSTANCE = new TVListAllocator();
+
+ private InstanceHolder() {}
}
public synchronized TVList allocate(TSDataType dataType) {
@@ -84,7 +88,7 @@ public class TVListAllocator implements TVListAllocatorMBean, IService {
@Override
public void start() throws StartupException {
try {
- JMXService.registerMBean(INSTANCE, mbeanName);
+ JMXService.registerMBean(InstanceHolder.INSTANCE, mbeanName);
} catch (Exception e) {
throw new StartupException(this.getID().getName(), e.getMessage());
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/UpgradeSevice.java b/server/src/main/java/org/apache/iotdb/db/service/UpgradeSevice.java
index df1c394..4468208 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/UpgradeSevice.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/UpgradeSevice.java
@@ -36,7 +36,6 @@ public class UpgradeSevice implements IService {
private static final Logger logger = LoggerFactory.getLogger(UpgradeSevice.class);
- private static final UpgradeSevice INSTANCE = new UpgradeSevice();
private ExecutorService upgradeThreadPool;
private AtomicInteger threadCnt = new AtomicInteger();
private static int cntUpgradeFileNum;
@@ -44,7 +43,13 @@ public class UpgradeSevice implements IService {
private UpgradeSevice() {}
public static UpgradeSevice getINSTANCE() {
- return INSTANCE;
+ return InstanceHolder.INSTANCE;
+ }
+
+ public static class InstanceHolder {
+ private static final UpgradeSevice INSTANCE = new UpgradeSevice();
+
+ private InstanceHolder() {}
}
@Override