This is an automated email from the ASF dual-hosted git repository.
neuyilan pushed a commit to branch rel/1.0
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.0 by this push:
new 5f57877d74 Fix concurrency problem (#9076) (#9080)
5f57877d74 is described below
commit 5f57877d7450227e1e1cd35743d263fa6c3bfa9e
Author: ZhangHongYin <[email protected]>
AuthorDate: Fri Feb 17 11:25:56 2023 +0800
Fix concurrency problem (#9076) (#9080)
---
.../java/org/apache/iotdb/metrics/AbstractMetricService.java | 12 ++++++++----
.../apache/iotdb/commons/service/metric/MetricService.java | 10 ++++++----
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git
a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
index c2684d9922..3875850cd0 100644
---
a/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
+++
b/metrics/interface/src/main/java/org/apache/iotdb/metrics/AbstractMetricService.java
@@ -77,15 +77,19 @@ public abstract class AbstractMetricService {
/** Start metric service. */
public void startService() {
startCoreModule();
- for (IMetricSet metricSet : metricSets) {
- metricSet.bindTo(this);
+ synchronized (this) {
+ for (IMetricSet metricSet : metricSets) {
+ metricSet.bindTo(this);
+ }
}
}
/** Stop metric service. */
public void stopService() {
- for (IMetricSet metricSet : metricSets) {
- metricSet.unbindFrom(this);
+ synchronized (this) {
+ for (IMetricSet metricSet : metricSets) {
+ metricSet.unbindFrom(this);
+ }
}
stopCoreModule();
}
diff --git
a/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
b/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
index c8f3cbdeda..5e5a427f6d 100644
---
a/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
+++
b/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/MetricService.java
@@ -62,10 +62,12 @@ public class MetricService extends AbstractMetricService
implements MetricServic
stopCoreModule();
internalReporter.clear();
startCoreModule();
- for (IMetricSet metricSet : metricSets) {
- LOGGER.info("MetricService rebind metricSet: {}",
metricSet.getClass().getName());
- metricSet.unbindFrom(this);
- metricSet.bindTo(this);
+ synchronized (this) {
+ for (IMetricSet metricSet : metricSets) {
+ LOGGER.info("MetricService rebind metricSet: {}",
metricSet.getClass().getName());
+ metricSet.unbindFrom(this);
+ metricSet.bindTo(this);
+ }
}
LOGGER.info("MetricService restart successfully.");
}