This is an automated email from the ASF dual-hosted git repository.
vongosling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/master by this push:
new 0f76489 [ROCKETMQ-290] Fix memory leak in
WaitNotifyObject#waitingThreadTable (#178)
0f76489 is described below
commit 0f76489882d3954fd640e28c7b8704b6d9f3096f
Author: Jason918 <[email protected]>
AuthorDate: Sat Jul 14 11:01:42 2018 +0800
[ROCKETMQ-290] Fix memory leak in WaitNotifyObject#waitingThreadTable (#178)
---
.../org/apache/rocketmq/store/ha/HAConnection.java | 2 +
.../apache/rocketmq/store/ha/WaitNotifyObject.java | 7 ++++
.../rocketmq/store/ha/WaitNotifyObjectTest.java | 43 ++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java
b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java
index 8b97504..ddae12e 100644
--- a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java
+++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java
@@ -300,6 +300,8 @@ public class HAConnection {
}
}
+
HAConnection.this.haService.getWaitNotifyObject().removeFromWaitingThreadTable();
+
if (this.selectMappedBufferResult != null) {
this.selectMappedBufferResult.release();
}
diff --git
a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java
b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java
index 6aba375..a4c34cb 100644
--- a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java
+++ b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java
@@ -96,4 +96,11 @@ public class WaitNotifyObject {
}
}
}
+
+ public void removeFromWaitingThreadTable() {
+ long currentThreadId = Thread.currentThread().getId();
+ synchronized (this) {
+ this.waitingThreadTable.remove(currentThreadId);
+ }
+ }
}
diff --git
a/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java
b/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java
new file mode 100644
index 0000000..99e4432
--- /dev/null
+++ b/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.store.ha;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class WaitNotifyObjectTest {
+ @Test
+ public void removeFromWaitingThreadTable() throws Exception {
+ final WaitNotifyObject waitNotifyObject = new WaitNotifyObject();
+ for (int i = 0; i < 5; i++) {
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ waitNotifyObject.allWaitForRunning(100);
+ waitNotifyObject.removeFromWaitingThreadTable();
+ }
+ });
+ t.start();
+ t.join();
+ }
+ Assert.assertEquals(0, waitNotifyObject.waitingThreadTable.size());
+ }
+
+}