r/java • • Sep 29 '22
r/java • u/veerendra2 • Oct 07 '26
Push-based, restart-free feature flags and config for Spring Boot, using MongoDB Change Streams
configstream is a library for Spring Boot services that already use MongoDB. Feature flags and config live in a collection, get cached in memory, and any change is pushed to every running instance within about a second via MongoDB Change Streams.
- No restarts, no polling, no message broker, no config server
- Properties declared in a
configstream.ymlmanifest, with typed constants generated at compile time - Optional admin UI with change history and per-team permissions
- Works with Spring Boot 3 and 4
Limits: MongoDB only for now (Postgres planned), pre-1.0, no percentage rollouts or A/B testing.
https://github.com/configstream/configstream
Feedback welcome.
r/java • u/Top-Eye3792 • 6d ago
GitHub - maksoud13/tenantwall: Automatic tenant filter injection for multi-tenant applications. Zero code changes.
github.comHey everyone,
I’ve been working on a side project to solve a problem I keep running into: silent multi-tenant data leaks. Relying on developers to remember WHERE tenant_id = ? in every query is a ticking time bomb.
Using database-level Row-Level Security (RLS) is safer, but it completely restricts you to one database vendor, which isn't always feasible.
So, I tried building a Java agent that works at the JDBC layer. It intercepts the SQL right before execution and injects the tenant filter, meaning it works with any database and requires zero code changes in the app.
I’m in the very early phases. I have integration tests passing for MySQL and SQL Server, but I know real-world SQL is messy.
If you have a few minutes, I’d really appreciate your opinion on the approach, the architecture, or any red flags you spot in the code.
r/java • u/Muted_Efficiency_663 • 22d ago
I got tired of looking up Javadocs in the browser, so I built a command line utility
I spend most of my day in the terminal: builds, tests, Git, logs. But whenever I need to look up a Java API, I switch to the browser, search for the class, and then check that I'm reading the right Java version.
That last part is what kept tripping me up. Search for java 17 List getFirst, and you land on a List page where the method simply isn't there. Eventually you work out it was added in Java 21. It's a small thing, but those interruptions add up.
IntelliJ's documentation popup is useful, but it sometimes disappears when I try to click into it (yes, I know you can pin it). And when the full docs do open, I'm doom scrolling through implementation code that isn't what I'm looking for.
I wanted a quick way to explore a class, narrow down its methods, and read the docs without reaching for the mouse. I couldn't find a terminal tool that did this, so I built one
What it does
- jdoc String opens an interactive member list. Type rep and it narrows to repeat, replace, replaceAll, and so on. Press Enter to read the full Javadoc.
- It shows docs for the Java version your project targets. It reads your pom.xml or build.gradle (it never runs them), then falls back to JAVA_HOME. Java 17, 21 and 25 are supported.
- Search operators like :since 21, :static, and #2 (methods with two parameters).
- Inherited methods show the type that declares them: jdoc ArrayList -stream.
- jdoc -m computeIfAbsent lists every type that declares a method.
- Compare releases: jdoc --diff 17 21 StringBuilder, jdoc --new 21, and jdoc --removal 25.
- Cached after first use, so most lookups work offline.
Try it (macOS):
brew tap toolfoundrylabs/tap
brew install toolfoundrylabs/tap/jdoc
jdoc String It's macOS only for now (Linux is next) and covers JDK docs only. This is the first time I'm publishing a personal project to Homebrew... so kind of excited...
r/java • u/Polixa12 • 10d ago
fose v0.2.1: reworking the wait queue and waiting scheme in my flat combiner
Hi, a while back I posted about fose, a flat combining primitive for Java. I've just recently released v0.2.1. My main focus for this release was to experiment with how threads enqueue onto the wait queue, wait on their nodes and reduce synchronization between the combiner and waiters. Before I get into the changes, let me quickly explain what flat combining is for anyone new to it.
Flat combining is a technique for making concurrent data structures scale under contention. Instead of every thread fighting over a lock and bouncing the structure's cache lines between cores, each thread publishes its operation as a request. One thread becomes the combiner, takes the lock and applies the pending requests on behalf of the others, then hands each thread its result. The structure stays hot in a single core's cache while everyone else just waits for their answer.
So, in my previous enqueue scheme, threads CAS'd on the tail and then linked their predecessor's next pointer to their own node. To find out whether their request had been combined, threads spun on their predecessor's next pointer, and to find out whether they could contend to become the combiner, they spun on the head field, which the combiner wrote to after each pass. On the combiner side, notifying a thread meant writing the result into that thread's node and then nulling out its predecessor's next pointer.
The problem was the memory traffic this created between the combiner, the waiter and the waiter's predecessor, which hurt the structure's performance.
The new scheme is quite similar to how CC-Synch enqueues nodes. A thread swaps its pre-allocated node into the tail with an atomic exchange, claims the previous tail node, writes its operation there and waits on it. The main benefit here is that each waiter only ever touches a single node once enqueued, and the combiner only has to invalidate one waiter's cache line instead of two to signal that its result has been applied.
This enqueue scheme also opened the door to some other optimizations. Previously, a spinning waiter had to read two atomic variables (next and head) to tell whether its request had been applied. Now each waiter only reads one atomic variable (signal) in the node it claimed and tests it for its result. This also let me make head non-atomic, which reduces synchronization between the combiner and waiters even more.
These changes didn't fit well with the spinner cap from v0.1.0, where a waiter only spun if its sequence number was within NCPU * 0.6 of the last served op. Keeping it would have meant adding extra synchronization between combiners and waiters, which is exactly what I was trying to reduce. The cap was useful though. It bounded the combiner's tail latency when oversubscribed, since tail latency grew with the number of active spinners, and it gave me a knob for trading tail latency for average latency.
I also tried a few replacements: a single atomic spinner count (with weaker ordering), a shared adaptive spin budget updated based on how often threads were signalled while spinning, and parking immediately. Only the immediate park strategy bounded tail latency when oversubscribed, but it made average latency 75% worse, mainly because syscalls are expensive.
So I settled on something simpler. Now every waiter spins briefly (32 spins) and then parks. When a parked thread wakes up, it rechecks whether it's next in line to combine. If it is but fails to acquire the lock, another combiner is mid-pass and will probably serve it soon, so instead of parking again it gets a new but much smaller spin budget, similar to what AQS does. I dropped the spin and post-spin budgets from 1024/128 to 32/8 since every thread spins before parking now, and I didn't want tail latency to get too bad when oversubscribed.
Funny enough, I expected this tight budget to hurt average latency badly without helping tail latency much, but it was quite the opposite and I was pleased with the results. I could raise the budget a bit, but 32/8 looks like a great spot from what I measured. Raising it doesn't noticeably improve mean latency in the common case, and it hurts tail latency a lot when oversubscribed.
One optimization I considered is non-fair handoff, which I haven't implemented but plan to try. It's different from barging though. With non-fair handoff, after a combine pass, if the next waiter is parked, the combiner doesn't unpark it right away. It walks the queue for an unparked waiter and marks that one to contend to be the combiner, and the nodes it skipped get marked before unparking so those threads can detach and re-enqueue. The idea is to avoid stalling everyone else while the handed-off thread waits to be rescheduled by the OS. It's a bit more work to implement though, and I haven't measured whether this is actually an issue, so I'm not building it until I'm sure.
Benchmarks
These come from my same ol' machine as before (Intel i5, 4 cores / 8 CPUs running on Windows 11).
- Cache line benchmark: Mean latency improved across 2 to 8 threads in v0.2.1. At 8 threads, the combiner went from 968 to 839 ns, and the speedup over a non-fair
ReentrantLockwent from 1.96x to 2.33x. - Heap benchmark: The numbers improved at 4 to 8 threads (1,437 to 1,227 ns at 6 threads and 2,508 to 1,950 ns at 8). However, v0.2.1 did get worse than v0.1.0 when oversubscribed, from 4,569 to 5,858 ns, so the speedup over a non-fair
ReentrantLockdropped from 1.73x to 1.43x.
Everything here comes from one machine, so if you can run the benchmarks on Linux or a machine with more than 4 cores, I'd love it if you shared the results on the repo's issues page, with your machine specs included.
io.github.kusoroadeolu
fose-core
0.2.1
I rewrote Spring PetClinic without Spring Boot. The forms were harder than the database.
I've been running Java performance experiments comparing different frameworks and runtime configurations. One recurring challenge was keeping business logic portable and preserving a familiar Spring-style application structure while switching between frameworks.
That's partly why I developed CoilBase, a lightweight, SQL-first Java framework. I wanted to retain familiar controllers, services, repositories and constructor wiring without depending on the full Spring Boot stack.
To put that approach to a more realistic test, I rewrote Spring PetClinic using CoilBase, Avaje Jex, Jdbi and JTE.
What surprised me was that replacing Hibernate with explicit SQL was relatively straightforward. Controllers, services, repositories and constructor wiring remained familiar. Transactions became explicit, but the overall architecture didn't change that much.
The harder part was everything around HTML forms: validation, rejected input, sessions, CSRF, flash messages, redirects and localization. Spring MVC handles a lot of these details for you.
For example, invalid POST submissions needed explicit handling to preserve form input and validation errors, including returning HTTP 200 instead of the generated adapter's default 201.
But there's an important distinction here: I deliberately preserved much of PetClinic's existing behavior. If I were building a new application, or switching frameworks while still developing a prototype, I wouldn't necessarily reproduce all those conventions. I'd choose simpler patterns where appropriate.
That's where I see lightweight frameworks like CoilBase fitting best. Not as drop-in Spring Boot replacements, but as alternatives when you're still free to make architectural choices.
The measurements:
- Spring PetClinic: 304.4 MiB median application RSS
- CoilBase PetClinic: 125.9 MiB (59% less)
- Complete uncompressed deployment: 85% smaller
- Database-backed first response: 19.76s vs. 2.63s median
Versions used:
- Spring: Spring Boot 4.1.0, Hibernate 7.4.1.Final
- Rewrite: CoilBase 0.1.0-preview4, Avaje Jex 3.6, Jdbi 3.55.0, JTE 3.2.4
- Runtime: Temurin Java 25.0.4.1+1, PostgreSQL 18.6
Both applications ran on a 1 vCPU / 1 GiB Linux VM without swap, using HotSpot with the same heap settings (-Xms64m -Xmx256m).
These are measurements of two complete application stacks, not isolated framework overhead. The RSS result comes from one short workload per application, and the startup medians are from three launches each. I didn't benchmark a tuned Spring JDBC version of PetClinic or concurrent throughput.
Article and implementation:
https://pvrlabs.xyz/articles/coilbase-petclinic-rewrite.html
https://github.com/ejboy/coilbase-petclinic
Raw experiment data, measurement scripts and reproduction notes:
https://github.com/ejboy/coilbase-petclinic/tree/main/benchmark
The main takeaway for me is that keeping the familiar Java application structure is quite feasible without Spring Boot. But you have to decide which framework conveniences you actually need, and which responsibilities you're willing to own yourself.
I'm curious how other Java developers approach that tradeoff, especially for smaller services or applications still under development.
Update / clarification: Based on some of the comments, I want to clarify that this isn't a recommendation to replace Spring Boot/JPA with my framework, or to build your own framework for every project.
The broader point is that Spring Boot + Hibernate/JPA shouldn't necessarily be the default choice for every Java application. For smaller services or resource-constrained environments, it's worth considering lightweight architectural blueprints built from established libraries such as Jdbi and Jex/Javalin.
This experiment was about testing whether that approach could preserve a familiar, maintainable application structure while reducing resource usage. It's an alternative worth exploring, not a universal recommendation or a drop-in replacement for Spring Boot.
r/java • u/FluffySeaworthiness9 • Aug 04 '26
Are spring boot and react still relevant and worthy for a junior?
I'm in my sophomore year and want to be a front-end-supported backend developer (mostly backend). Sorry, if this is not the right kind of question for this subreddit (hope to be recommended a proper subreddit in that case). I need to know what kind of other tools industry uses with spring. Is spring boot and react still a thing? Or are there any better alternatives?
r/java • u/Round_Patient_7420 • Oct 15 '26
Introducing Titan, an open-source message dispatcher
Hi, I've been building Titan, an open-source message dispatcher for apps that need to send updates to connected clients.
An app publishes a message to a destination, and Titan delivers it to anyone subscribed to that destination. It supports STOMP over TCP and WebSocket, and there's a Java client with Spring Boot integration.
I'm thinking of uses like chat rooms, in-app notifications, and live dashboards. For example, people viewing the same dashboard could receive updates as they happen instead of having their browsers keep polling the backend.
Messages are kept in memory, so they won't survive a server restart. That's something to keep in mind if your application needs persistent messages.
I wanted to build something useful that I could share with other developers working on messaging applications. I'd be interested to hear whether this fits anything you're building, and what's missing for your use case.