diff --git a/pom.xml b/pom.xml
index fbde7f6..0a869a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
it.cavallium
filequeue
file queue project
- 3.1.8
+ 3.1.9
jar
Light weight, high performance, simple, reliable and persistent queue
4.0.0
diff --git a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java
index bcc1493..ba73452 100644
--- a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java
+++ b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java
@@ -24,7 +24,6 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
private final String name;
private final Serializer serializer;
private final Deserializer deserializer;
- private final Arena arena;
private final long segmentSize;
public SimpleQueueMemorySegment(Path directory,
@@ -32,7 +31,6 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
Serializer serializer,
Deserializer deserializer,
long segmentSize) throws IOException {
- this.arena = Arena.ofShared();
this.name = name;
this.directory = directory;
this.serializer = serializer;
@@ -74,7 +72,7 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
private SimpleQueueMemorySegmentFixedSize expandQueueSegmentForWrite() throws IOException {
synchronized (queueSegments) {
- var queueMemorySegment = new SimpleQueueMemorySegmentFixedSize(arena, segmentSize, generateQueuePath());
+ var queueMemorySegment = new SimpleQueueMemorySegmentFixedSize(segmentSize, generateQueuePath());
// Hibernate the middle segments, if there will be 3 or more segments after the expansion
if (queueSegments.size() >= 2) {
queueSegments.getLast().hibernate();
@@ -157,7 +155,6 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
e.printStackTrace();
}
});
- this.arena.close();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
diff --git a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
index 23087d5..135c69b 100644
--- a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
+++ b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
@@ -18,26 +18,30 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
private final Path filePath;
private final FileChannel ch;
private final MemorySegment writer;
- private final Arena arena;
+ private final Arena mmapArena;
private final long fixedSize;
private long readPosition = 0;
private long writePosition = 0;
private final AtomicInteger size = new AtomicInteger();
- public SimpleQueueMemorySegmentFixedSize(Arena arena, long fixedSize, Path filePath) throws IOException {
- this.arena = arena;
+ public SimpleQueueMemorySegmentFixedSize(long fixedSize, Path filePath) throws IOException {
+ this.mmapArena = Arena.ofShared();
this.filePath = filePath;
this.fixedSize = fixedSize;
Files.deleteIfExists(filePath);
this.ch = FileChannel.open(filePath, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.READ);
ch.truncate(fixedSize);
- this.writer = ch.map(MapMode.READ_WRITE, 0L, fixedSize, arena);
+ this.writer = ch.map(MapMode.READ_WRITE, 0L, fixedSize, mmapArena);
}
@Override
public void close() throws IOException {
- ch.close();
- Files.deleteIfExists(filePath);
+ try {
+ ch.close();
+ Files.deleteIfExists(filePath);
+ } finally {
+ mmapArena.close();
+ }
}
public void add(MemorySegment element) {