Hibernation

This commit is contained in:
Andrea Cavalli 2023-10-20 13:04:30 +02:00
parent a359656ca9
commit 09519997dc
3 changed files with 9 additions and 1 deletions

View File

@ -4,7 +4,7 @@
<groupId>it.cavallium</groupId>
<artifactId>filequeue</artifactId>
<name>file queue project</name>
<version>3.1.6</version>
<version>3.1.7</version>
<packaging>jar</packaging>
<description>Light weight, high performance, simple, reliable and persistent queue</description>
<modelVersion>4.0.0</modelVersion>

View File

@ -73,6 +73,10 @@ public class SimpleQueueMemorySegment<T> implements SimpleQueue<T>, Closeable {
private SimpleQueueMemorySegmentFixedSize expandQueueSegmentForWrite() throws IOException {
synchronized (queueSegments) {
var queueMemorySegment = new SimpleQueueMemorySegmentFixedSize(arena, segmentSize, generateQueuePath());
// Hibernate the middle segments, if there will be 3 or more segments after the expansion
if (queueSegments.size() >= 2) {
queueSegments.getLast().hibernate();
}
queueSegments.add(queueMemorySegment);
return queueMemorySegment;
}

View File

@ -86,4 +86,8 @@ public class SimpleQueueMemorySegmentFixedSize implements Closeable {
public int size() {
return Math.max(0, size.get());
}
public void hibernate() {
this.writer.unload();
}
}