diff --git a/pom.xml b/pom.xml
index f86fee7..fbde7f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
it.cavallium
filequeue
file queue project
- 3.1.7
+ 3.1.8
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 bdeaa43..bcc1493 100644
--- a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java
+++ b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegment.java
@@ -60,13 +60,15 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
- var memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE, serialized);
- try {
- if (!getQueueSegmentForWrite().offer(memorySegment)) {
- expandQueueSegmentForWrite().add(memorySegment);
+ try (var arena = Arena.ofConfined()) {
+ var memorySegment = arena.allocateArray(ValueLayout.JAVA_BYTE, serialized);
+ try {
+ if (!getQueueSegmentForWrite().offer(memorySegment)) {
+ expandQueueSegmentForWrite().add(memorySegment);
+ }
+ } catch (IOException ex) {
+ throw new UncheckedIOException(ex);
}
- } catch (IOException ex) {
- throw new UncheckedIOException(ex);
}
}
@@ -118,18 +120,18 @@ public class SimpleQueueMemorySegment implements SimpleQueue, Closeable {
@Override
public T remove() {
MemorySegment removed;
- try {
- removed = getQueueSegmentForRead().poll();
+ try (var arena = Arena.ofConfined()) {
+ removed = getQueueSegmentForRead().poll(arena);
if (removed == null) {
if (popQueueSegmentForRead()) {
- removed = getQueueSegmentForRead().poll();
+ removed = getQueueSegmentForRead().poll(arena);
}
}
+ if (removed == null) throw new NoSuchElementException();
+ return readObject(removed.toArray(ValueLayout.JAVA_BYTE));
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
- if (removed == null) throw new NoSuchElementException();
- return readObject(removed.toArray(ValueLayout.JAVA_BYTE));
}
private T readObject(byte[] byteBuffer) {
diff --git a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
index 0dd4b11..23087d5 100644
--- a/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
+++ b/src/main/java/it/cavallium/filequeue/SimpleQueueMemorySegmentFixedSize.java
@@ -62,7 +62,7 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
return true;
}
- public MemorySegment poll() {
+ public MemorySegment poll(Arena arena) {
if (readPosition >= fixedSize) {
return null;
}
@@ -77,8 +77,8 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
return segment;
}
- public MemorySegment remove() {
- var polled = poll();
+ public MemorySegment remove(Arena arena) {
+ var polled = poll(arena);
if (polled == null) throw new NoSuchElementException();
return polled;
}