This workshop project demonstrates Java's Foreign Function & Memory API (Project Panama) using Java 25. It focuses on interoperating with native C libraries, specifically POSIX message queues.
- Java 25 (Temurin 25+36-LTS)
- Maven 3.9.11+
- Task (Taskfile runner) - Installation instructions
- direnv (optional, for automatic environment setup)
If using direnv and SDKMAN:
direnv allow # Automatically activates Java 25 and Maven 3.9.11Or manually:
sdk use java 25-tem
sdk use maven 3.9.11task # Downloads jextract and builds all modulesThe foreign-posix-queue module includes two example programs that demonstrate inter-process communication using POSIX message queues.
In one terminal, start the receiver process:
task run-posix-receiverThe receiver will:
- Open/create a POSIX message queue named
/queue - Display queue attributes (max messages, message size)
- Wait for incoming messages
- Print each received message to stdout
In another terminal, start the sender process:
task run-posix-senderThe sender will:
- Open the same POSIX message queue (
/queue) - Prompt you to type messages
- Send each line you type to the receiver
- Exit when you press Ctrl+D or Ctrl+C
Terminal 1 (Receiver):
$ task run-posix-receiver
opened POSIX queue /queue with attributes (max message: 10) (max message size: 8192 bytes)
Message received: Hello from sender!
Message received: Testing POSIX queues
Message received: This is awesome!
Terminal 2 (Sender):
$ task run-posix-sender
Opened POSIX queue /queue for sending messages
Type messages and press Enter to send (Ctrl+D or Ctrl+C to exit):
Hello from sender!
Message sent: Hello from sender!
Testing POSIX queues
Message sent: Testing POSIX queues
This is awesome!
Message sent: This is awesome!
^D
Sender shutting down...
If you see errors about jextract not being found:
task setup-jextract # Downloads jextract to .local/POSIX queues persist across process restarts. To clean up:
# Remove the queue manually
rm /dev/mqueue/queueEnsure you have permissions to create/access POSIX queues on your system.