Spring / Spring Boot 4 Basics Interview Questions
What are @Retryable and @ConcurrencyLimit in Spring Boot 4 and how do they work?
Spring Boot 4 (via Spring Framework 7) brings built-in resilience patterns directly into the Spring context. Previously, retry required the separate spring-retry dependency plus @EnableRetry. Spring Boot 4 ships these capabilities as first-class features.
// Spring Boot 3 (required separate dependency + @EnableRetry): // pom.xml: spring-retry dependency // Config class: @EnableRetry @Service public class StockService { @Retryable(value = {NetworkException.class}, maxAttempts = 2) public void updateStock() { ... } } // Spring Boot 4: works out of the box with spring-boot-starter-resilience // No @EnableRetry needed! @Service public class StockService { // Retry with exponential backoff and jitter @Retryable( includes = NetworkException.class, // exception types to retry on maxRetries = 3, // number of retry attempts backoff = @Backoff( delay = 500, // initial delay in ms multiplier = 2.0, // exponential multiplier random = true // add jitter ) ) public Order fetchOrderFromRemote(String orderId) { return remoteService.fetch(orderId); // automatically retried on NetworkException } // Bulkhead pattern: limit concurrent callers @ConcurrencyLimit(limit = 5) // max 5 concurrent executions public void processPayment(Payment payment) { // Only 5 threads can execute this simultaneously // 6th caller blocks until one slot frees up paymentGateway.process(payment); } // Combining both: @Retryable(includes = NetworkException.class, maxRetries = 3) @ConcurrencyLimit(limit = 10) public void updateStock() { externalInventoryApi.update(); } }
@ConcurrencyLimit implements the Bulkhead pattern from resilience engineering. It is particularly valuable with virtual threads (Java 21+), where it prevents a burst of cheap virtual threads from overwhelming a downstream service with simultaneous requests.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
