Persistent java.util.Queue implementation with Xodus
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ralph Schaer edabf809e9 upgrade
2026-10-04 10:09:20 +02:00
.github/workflows upgrade 2026-08-30 20:56:11 +02:00
.mvn/wrapper upgrade 2026-05-31 15:48:30 +02:00
src Fix queue contracts and strengthen concurrency tests 2026-09-03 20:53:13 +02:00
.editorconfig Initial commit 2018-05-13 06:39:34 +02:00
.gitignore Enhance XodusQueue with capacity validation and update tests; modify .gitignore and README for clarity 2026-06-08 04:49:13 +02:00
.project Fix concurrency issues 2025-09-06 08:32:29 +02:00
LICENSE Initial commit 2018-05-13 06:12:34 +02:00
mvnw Upgrade 2025-07-26 12:41:16 +02:00
mvnw.cmd Upgrade 2025-07-26 12:41:16 +02:00
mySettings.xml Switch from Travis to GitHub Actions 2019-12-03 03:06:51 +01:00
pom.xml upgrade 2026-10-04 10:09:20 +02:00
README.md Enhance XodusQueue with capacity validation and update tests; modify .gitignore and README for clarity 2026-06-08 04:49:13 +02:00
Taskfile.yml Fix concurrency issues 2025-09-06 08:32:29 +02:00

Test Status

This project provides a persistent java.util.Queue and java.util.concurrent.BlockingQueue implementation. It is using Xodus as the underlying storage engine. For persisting POJOs, it relies on Kryo.

xodus-queue is not a high-performance queue, and it only works within a single JVM. The primary motivation was to write a queue that survives a server restart and does not introduce a lot of external dependencies to my projects. Because I often use Xodus already in my projects, this library only adds Kryo as an additional dependency.

Any contributions are welcome if something is missing or could be implemented better, submit a pull request, or create an issue.

Usage

Create an instance of XodusQueue or XodusBlockingQueue and specify the database directory and the class of the entries you want to put into the queue. These can be either built-in Java types like String, Integer, Long, or a more complex POJO.

It is recommended to open the queue in an automatic resource management block because the underlying Xodus database should be closed when you no longer access the queue.

try (XodusQueue<String> queue = new XodusQueue<>("./test", String.class)) {

}

After the instantiation, you can call any of the methods from the java.util.Queue<E> and java.util.concurrent.BlockingQueue<E> interface. See the JavaDoc (Queue, BlockingQueue) for a list of all available methods.

The iterator() method returns a snapshot of the queue contents at the time the iterator is created.

try (XodusQueue<String> queue = new XodusQueue<>("./queue", String.class)) {
  queue.add("one");

  String head = queue.poll(); // "one"
}

The blocking queue supports a capacity limit. The following example limits the number of elements in the queue to 3. put blocks the current thread when the queue is full and take blocks when the queue is empty. The capacity must be greater than zero.

try (XodusBlockingQueue<String> queue = new XodusBlockingQueue<>("./blocking_queue", String.class, 3)) {
  queue.put("one");
  queue.put("two");

  String head = queue.take(); // "one"
}

Maven

The library is hosted on the Central Maven Repository

  <dependency>
    <groupId>ch.rasc</groupId>
    <artifactId>xodus-queue</artifactId>
    <version>2.0.0</version>
  </dependency>

Changelog

2.0.0 - Sep 6, 2025

  • Minimum Java 17
  • Fix concurrency issues
  • Upgrade Kryo library

1.0.1 - May 19, 2018

  • Fix key management in XodusQueue
  • Add java.util.concurrent.BlockingQueue implementation: XodusBlockingQueue

1.0.0 - May 15, 2018

  • Initial release

License

Code released under the Apache license.