Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

What is the difference between Mono.just(loadUser()) and Mono.fromCallable(() -> loadUser())?

Mono.just(loadUser()) calls loadUser() immediately, on the current thread, while the pipeline is being assembled, even if nobody ever subscribes, and every subscriber then gets that same captured value. Mono.fromCallable(() -> loadUser()) only stores the lambda and calls it when someone subscribes, once per subscriber, and a null result becomes an empty Mono, whereas Mono.just(null) throws a NullPointerException. Mono.defer gives the same laziness when the code returns a publisher, and getting this wrong is a common cause of unexpected blocking and side effects in reactive code.

Background to this question

This is one of the first questions about Reactor that reveals whether someone understands the difference between building a pipeline and running it. The two lines look almost the same, and the code using them often passes tests, yet one of them may block an event loop thread or send an email that should never have been sent. In this answer, we will recap assembly time and subscription time, compare the two calls step by step with a runnable example, look at null handling and Mono.defer, and see the production bugs that come from eager evaluation.

1A Quick Recap: Assembly Time and Subscription Time

A Mono is a description of work that produces at most one value. Building that description is called assembly: we call factory methods and operators, and each returns a new Mono object. Nothing runs yet. The work happens at subscription time, when something subscribes, for example WebFlux subscribing to the Mono returned by a controller. A Mono can be subscribed many times, and each subscription normally runs the work again.

Java, however, evaluates method arguments before calling the method. That plain Java rule is the key to this question: whatever we pass into a Reactor factory as an argument has already been computed by the time Reactor sees it.

2Mono.just Runs the Call During Assembly

Mono.just(value) wraps a value we already have. When we write Mono.just(loadUser()), Java first calls loadUser(), and only then passes the result to Mono.just.

Java
User loadUser() {
System.out.println("loading on " + Thread.currentThread().getName());
return repository.findBlocking(42); // blocking JDBC call, 50 ms
}
Mono<User> eager = Mono.just(loadUser()); // loading on reactor-http-nio-3 (runs NOW)
System.out.println("assembled"); // assembled
eager.subscribe(u -> System.out.println(u.name())); // Alice (no new load)
eager.subscribe(u -> System.out.println(u.name())); // Alice (still no new load)

Notice three consequences. The load happens even if the Mono is never subscribed, for example when a later condition picks another branch. It happens on whatever thread is assembling the pipeline, which in WebFlux is often a Netty event loop thread that must never block. And the value is captured once, so a retry or a second subscriber gets the same, possibly stale, user rather than loading it again.

3Mono.fromCallable Defers the Call Until Subscription

Mono.fromCallable takes a Callable, a lambda that Reactor can call later. Assembly only stores the lambda. Each subscription calls it, and the result, or the exception it throws, becomes the Mono's signal.

Java
Mono<User> lazy = Mono.fromCallable(() -> loadUser()); // nothing printed
System.out.println("assembled"); // assembled
lazy.subscribeOn(Schedulers.boundedElastic()) // run the blocking call off the event loop
.subscribe(u -> System.out.println(u.name())); // loading on boundedElastic-1, then Alice
lazy.subscribe(u -> System.out.println(u.name())); // loading on main, then Alice (loaded again)
Mono.fromCallable(() -> loadUser()).retry(2); // each retry calls loadUser() again
Mono.just against Mono.fromCallable
QuestionMono.just(loadUser())Mono.fromCallable(() -> loadUser())
When does loadUser() run?at assembly, before Reactor sees itat each subscription
Runs with no subscriber?yesno
Which thread?the assembling threadthe subscribing thread or subscribeOn
Second subscriber or retryreuses the captured valuecalls loadUser() again
loadUser() returns nullNullPointerException at assemblyempty Mono
loadUser() throwsexception escapes assemblyonError signal

Because the call happens at subscription, we can move it to another thread with subscribeOn, which is the recommended way to wrap a blocking call, and retry() really retries. Exceptions thrown inside the callable become onError signals instead of escaping during assembly.

4Null Handling

Reactive Streams forbids null items, so Mono.just(null) throws a NullPointerException straight away. Mono.fromCallable is friendlier: if the callable returns null, the Mono completes empty, which fits methods that return null for not found. If we want just-like behaviour that tolerates null, Mono.justOrEmpty(value) wraps a possibly null value or an Optional, but it is still eager.

Java
Mono.fromCallable(() -> null).hasElement().subscribe(System.out::println); // false
Mono.justOrEmpty(null).hasElement().subscribe(System.out::println); // false
Mono.just(null); // NullPointerException

5Mono.defer for Code That Returns a Publisher

Sometimes the code we want to delay does not return a value but a Mono, for example a reactive repository call whose arguments depend on the current state, or a method with side effects before it returns its Mono. Mono.defer(() -> ...) takes a supplier of a Mono and calls it at each subscription, so building the inner publisher is delayed in the same way that fromCallable delays computing a value. Its close relative Mono.fromSupplier works like fromCallable for suppliers that do not throw checked exceptions.

Java
Mono<User> user = Mono.defer(() -> cache.contains(42)
? Mono.just(cache.get(42)) // evaluated per subscription, so the cache is checked each time
: userRepository.findById(42L));

The general rule is simple. Use Mono.just for constants and values we already hold, and fromCallable, fromSupplier or defer for anything that does work, blocks, or has side effects.

6Follow-up questions

Is Mono.just ever the right choice inside a service?

Yes, for values already computed or cheap to compute and free of side effects, such as a constant, a request parameter or a value returned by a previous operator inside map or flatMap. The problem is only work that should be lazy.

Does wrapping in fromCallable make a blocking call non-blocking?

No. The call still blocks a thread when it runs. fromCallable only makes it lazy so that we can choose the thread with subscribeOn(Schedulers.boundedElastic()), keeping it off the event loop. Truly non-blocking code needs a reactive driver.

How can we detect eager blocking calls on event loop threads?

BlockHound, a Java agent from the Reactor team, detects blocking calls on non-blocking threads in tests and fails them with a clear error. Running it in integration tests catches most of these mistakes before production.

7Conclusion

In this answer, we saw that Mono.just(loadUser()) evaluates loadUser() at assembly time, because Java evaluates arguments first, so it runs even with no subscriber, on the assembling thread, and only once. Mono.fromCallable(() -> loadUser()) defers the call to subscription time and runs it per subscriber, which makes subscribeOn and retry work, turns a null result into an empty Mono where Mono.just(null) throws, and turns exceptions into onError. Mono.defer gives the same laziness for code that returns a publisher, and eager evaluation is a common source of unexpected blocking and side effects.

What to say in the interviewAbout 80 seconds aloud

Open with

The difference is when loadUser runs. With Mono.just(loadUser()), Java evaluates the argument first, so loadUser runs right there while the pipeline is being assembled, on whatever thread is building it, even if nobody ever subscribes, and the Mono just holds the resulting value.

Then, if they want more

Every subscriber and every retry gets that same captured value. With Mono.fromCallable, Reactor only stores the lambda and calls it at subscription time, once for each subscriber. That matters a lot in WebFlux.

If loadUser is a blocking JDBC call, Mono.just runs it on the Netty event loop during assembly, which is exactly what we must avoid; with fromCallable I can add subscribeOn boundedElastic so it runs on a thread meant for blocking work. Retries also actually retry, and exceptions become onError signals instead of escaping.

Null handling differs too: Mono.just(null) throws a NullPointerException, while a callable returning null gives an empty Mono. When the code returns a Mono rather than a value, Mono.defer does the same job and delays building the publisher.

So my rule is Mono.just only for values I already have, and fromCallable, fromSupplier or defer for anything that does work or has side effects, because eager evaluation is one of the most common causes of hidden blocking and unexpected side effects in reactive code.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the difference between Mono.just(loadUser()) and Mono.fromCallable(() ->...": https://scrivio-interview-library.netlify.app/spring-boot/reactive-fundamentals/831c2e5957/