skip to content

Scheduling, Async & Caching

The three declarative features built on proxies: @Async for off-thread execution, @Scheduled for periodic work, and the cache abstraction. Interviewers like this area because all three share the same proxy caveats and the same production failure modes.

part ofSpring Frameworkread it →
on this pageshow

explore

questions

page 2 of 2

You're designing async exception handling for a platform with many fire-and-forget @Async tasks (emails, audit writes, webhooks). How do you make failures observable and recoverable without falling into the 'silently swallowed' trap?

level: principalimportance: should knowfreq 35%

basics

~20 s

Don't rely on the default log-only handler. Register a custom AsyncUncaughtExceptionHandler (via AsyncConfigurer) that logs with context, emits metrics, and alerts or dead-letters. For work needing results or retries, return CompletableFuture and handle failures explicitly, and propagate trace/MDC context onto async threads.

open as a page

Describe the Cache and CacheManager SPI contracts. How does the annotation layer sit on top of them, and why does this abstraction matter?

level: principalimportance: should knowfreq 40%

basics

~20 s

CacheManager is a factory that returns named Cache instances (getCache(name), getCacheNames()). Cache is the store interface: get, put, evict, clear, and get(key, Callable) for atomic loading. The @Cacheable/@CacheEvict annotations are just declarative sugar over these two interfaces, so any provider that implements them plugs in unchanged.

open as a page

What design considerations and pitfalls arise around the TaskScheduler and thread pool when using programmatic/dynamic scheduling?

level: principalimportance: should knowfreq 30%

basics

~20 s

The default TaskScheduler is single-threaded, so tasks serialize and a slow one delays others. Supply your own ThreadPoolTaskScheduler with adequate size, handle graceful shutdown, make tasks idempotent, and add cluster coordination since Spring scheduling isn't cluster-aware.

open as a page

What are the risks of propagating RequestContextHolder / request-scoped beans across the async thread boundary, and how would you do it safely?

level: principalimportance: should knowfreq 30%

basics

~20 s

The HttpServletRequest and request-scoped beans live only for the request; once it completes the request/response may be recycled and its attributes cleared. Copying RequestContextHolder to a pool thread risks touching a dead request. Safer: extract the plain values you need before submitting, and pass them explicitly.

open as a page

What happens when a @Scheduled fixedDelay/fixedRate method throws an unchecked exception versus a cron method? How should you make scheduled jobs resilient?

level: principalimportance: should knowfreq 45%

basics

~20 s

An uncaught exception from a fixedDelay or fixedRate task is logged but the schedule keeps running — future executions still fire. Only if you use a one-shot future would it stop. Make jobs resilient by catching and handling exceptions inside the method rather than letting them propagate.

open as a page

Compare @EnableAsync's PROXY mode with mode=ASPECTJ. When would you choose ASPECTJ, and what's the cost?

level: principalimportance: nice to knowfreq 30%

basics

~20 s

PROXY (default) wraps beans in a proxy, so only external calls to public methods become async. ASPECTJ weaves the async advice into the bytecode, so self-invocation and non-public methods also work. ASPECTJ needs the AspectJ weaver and compile/load-time weaving setup, which is more complex.

open as a page

showing 31–36 of 36