What is the significance of the @Scheduled annotation in Spring?
@Scheduled runs Spring bean methods at fixed intervals or on cron expressions. Learn the options, cron fields, threading behaviour and how to avoid duplicate runs.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
@Scheduled runs Spring bean methods at fixed intervals or on cron expressions. Learn the options, cron fields, threading behaviour and how to avoid duplicate runs.
Add the Redis and cache starters, enable caching and annotate methods with @Cacheable to share a cache across instances. Includes TTL, serialisation and failure handling.
@CachePut runs a method every time and stores the return value in a Spring cache, keeping entries fresh after updates. It differs from @Cacheable, which can skip the call.
Build a custom Spring CacheManager with a TTL cache, register it as a bean and learn when Caffeine or Redis are the better choice.
@CacheEvict removes stale entries from a Spring cache when data changes. See its attributes, working examples and the pitfalls that stop it from working.
Add the cache starter, enable caching, annotate methods with @Cacheable, and pick a provider such as Caffeine or Redis through application.yml.
@Cacheable stores a method's return value in a Spring cache so later calls with the same arguments skip the method. See setup, attributes and pitfalls.
Understand the proxy rules, transaction timing and key design behind Spring caching so annotations like @Cacheable behave correctly in real applications.
Cross-cutting concerns such as logging, security and transactions touch many modules. See how AOP, interceptors and decorators separate them from business logic.
Wrap methods with an @Around aspect to time them accurately, scope it with a custom annotation, flag slow calls and publish timers to Micrometer.
@Pointcut defines a named, reusable expression in Spring AOP that selects which method executions advice applies to. Learn syntax, designators and limits.
Write an @Aspect with @Around advice that logs method calls, duration and exceptions, choose pointcuts and avoid proxy and sensitive data pitfalls.
Use @Around in Spring AOP to wrap bean methods for logging, timing, caching and retries, with a custom annotation example and the proxy pitfalls to avoid.
@Aspect marks a class that packages cross-cutting logic such as logging or security, with pointcuts and advice that Spring applies to beans through proxies.
Use JtaTransactionManager with Atomikos or Narayana and XA data sources for two-phase commit in Spring, and know when sagas or an outbox fit better.
REQUIRES_NEW makes Spring run a method in its own transaction, independent of the caller. Learn when to use it, with an audit example and pool risks.
Spring supports distributed transactions through JtaTransactionManager and XA resources, but microservices usually need sagas and the transactional outbox instead.
Queues deliver a message to one consumer, topics deliver it to every subscriber. See the differences with Jakarta Messaging examples and broker mappings.
Use Spring AMQP for RabbitMQ or Spring Kafka for Kafka. See configuration, producers, consumers and how to choose between the two brokers.
Spring AMQP gives Spring apps a template-and-listener model for RabbitMQ. See its core components, Java configuration, JSON messages and retry with dead-letter queues.