This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new ecfd17ae8 ORC-1600: Reduce getStaticMemoryManager sync block in OrcFile
ecfd17ae8 is described below
commit ecfd17ae8d995ce06958b53b1ffca9bccc9097a8
Author: sychen <[email protected]>
AuthorDate: Mon Jan 22 10:50:02 2024 -0800
ORC-1600: Reduce getStaticMemoryManager sync block in OrcFile
### What changes were proposed in this pull request?
Improve calling efficiency of
`org.apache.orc.OrcFile#getStaticMemoryManager`.
### Why are the changes needed?
`org.apache.orc.OrcFile#getStaticMemoryManager` is a static method with
synchronized. It needs to be locked every time it is called. This is
unnecessary.
### How was this patch tested?
GA
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #1768 from cxzl25/ORC-1600.
Authored-by: sychen <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit b5c2250f1e89629a1ce7d398e3567ea0713fd8cb)
Signed-off-by: Dongjoon Hyun <[email protected]>
---
java/core/src/java/org/apache/orc/OrcFile.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/OrcFile.java
b/java/core/src/java/org/apache/orc/OrcFile.java
index dfe3088fb..86444868b 100644
--- a/java/core/src/java/org/apache/orc/OrcFile.java
+++ b/java/core/src/java/org/apache/orc/OrcFile.java
@@ -1044,11 +1044,15 @@ public class OrcFile {
return new WriterOptions(tableProperties, conf);
}
- private static MemoryManager memoryManager = null;
+ private static volatile MemoryManager memoryManager = null;
- private static synchronized MemoryManager
getStaticMemoryManager(Configuration conf) {
+ private static MemoryManager getStaticMemoryManager(Configuration conf) {
if (memoryManager == null) {
- memoryManager = new MemoryManagerImpl(conf);
+ synchronized (OrcFile.class) {
+ if (memoryManager == null) {
+ memoryManager = new MemoryManagerImpl(conf);
+ }
+ }
}
return memoryManager;
}