Java Developer Interview Question

How would you run three independent remote calls at once and combine the results?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Either submit them to an executor of virtual threads and join the results, or compose them with CompletableFuture using supplyAsync on an explicit executor and allOf to wait. Set a timeout on the combined operation, handle partial failure deliberately, and cancel the siblings when one fails. Structured concurrency with a task scope expresses exactly this shape and ties the lifetime of the subtasks to the block, though it is still a preview API.

Why interviewers ask this

Fan out and join is the most common concurrency shape in a service, and the interviewer wants to see you handle the unglamorous parts: which executor the work runs on, what happens when one call fails or hangs, and whether the other calls get canceled. Knowing that the default asynchronous pool is the shared common pool, and why supplying your own executor matters, is the detail that separates real usage from tutorial usage.

How to structure your answer

  • Pick an approach and state where the tasks actually run.
  • Combine results and set an overall timeout.
  • Decide the partial failure policy explicitly.
  • Mention structured concurrency as the clearer modern shape.

Example answer

Spoken example, first person

With virtual threads this got simple: I open an executor that creates a thread per task, submit the three calls, then join each future. It reads sequentially, but the calls overlap, and each one has its own client timeout. If I am on an older codebase I use CompletableFuture with supplyAsync, and I always pass my own executor, because the default is the common ForkJoinPool which is sized for CPU work and shared by everything in the process. Then allOf to wait, and a timeout on the combined future so a hung dependency cannot hold the request forever. The part I think about hardest is partial failure: if the recommendations call fails, do I fail the whole page or render without them? Usually the answer is degrade, so that future gets an exceptionally handler returning an empty list, while the calls that are essential propagate. Structured concurrency expresses this much better, since a scope joins all subtasks and cancels the rest when one fails or the deadline passes, and I use it where a preview API is acceptable.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What executor does supplyAsync use if you do not pass one?
  • How do you cancel the other calls when one fails?
  • What is the difference between thenApply and thenCompose?

Related java developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot