Skip to content

Commit

Permalink
ORC-1600: Reduce getStaticMemoryManager sync block in OrcFile
Browse files Browse the repository at this point in the history
### 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 <sychen@ctrip.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit b5c2250)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
cxzl25 authored and dongjoon-hyun committed Jan 22, 2024
1 parent 1c48330 commit ecfd17a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions java/core/src/java/org/apache/orc/OrcFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,15 @@ public static WriterOptions writerOptions(Properties tableProperties,
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;
}
Expand Down

0 comments on commit ecfd17a

Please sign in to comment.