SpringBoot Super Scheduled: Dynamic Management and Enhancement of @Scheduled Tasks
This article introduces the SpringBoot‑Super‑Scheduled starter, explains how it dynamically manages native @Scheduled tasks without code changes, shows quick integration steps, and details the underlying implementation—including configuration management, post‑processor interception, dynamic proxy chaining, and runtime task control—complete with code examples.
SpringBoot‑Super‑Scheduled is a starter that enhances native SpringBoot @Scheduled tasks by providing dynamic management capabilities while remaining fully compatible with the original @Scheduled annotation.
Function description : It allows runtime control of scheduled jobs, such as modifying cron expressions, fixed delays, or fixed rates, and supports manual execution and termination.
Quick use : Add the dependency to your project:
<dependency>
<groupId>com.github.guoyixing</groupId>
<artifactId>spring-boot-starter-super-scheduled</artifactId>
<version>0.3.1</version>
</dependency>Configure the starter and obtain the source code from Gitee or GitHub.
Implementation principle :
1. Configuration management – a SuperScheduledConfig bean stores task metadata, thread pool, and mappings between task names and their runtime objects.
2. Post‑processor interception – a SuperScheduledPostProcessor implements BeanPostProcessor and ApplicationContextAware to scan beans for methods annotated with @Scheduled , capture their metadata into ScheduledSource , and disable the original scheduling by resetting annotation attributes.
@Component("superScheduledConfig")
public class SuperScheduledConfig { ... }3. ApplicationRunner initialization – SuperScheduledApplicationRunner creates a SuperScheduledRunnable for each captured task, builds a chain of Point proxies (each representing a strengthening interceptor), and schedules the task using ThreadPoolTaskScheduler .
@Component
@Order
public class SuperScheduledApplicationRunner implements ApplicationRunner, ApplicationContextAware { ... }4. Dynamic management – SuperScheduledManager provides APIs to modify cron, fixedDelay, or fixedRate at runtime, cancel existing tasks, and restart them with updated configurations.
public void setScheduledCron(String name, String cron) { ... }5. Strengthening interface – BaseStrengthen defines before, after, exception, and afterFinally hooks. Implementations are proxied via CGLIB ( RunnableBaseInterceptor ) and linked into a Chain to form an invocation pipeline.
public interface BaseStrengthen { void before(...); void after(...); void exception(...); void afterFinally(...); }6. Task execution – SuperScheduledRunnable executes the chain of strengtheners; when the chain is exhausted, it invokes the original method via reflection.
public Object invoke() { ... }The article also includes promotional sections urging readers to join a WeChat group, claim gifts, and scan QR codes, but the core technical content provides a complete guide for developers to integrate and control scheduled tasks dynamically.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.