- Depends on RedissonClient: communicates only with Redis, without additional server overhead (considering adding a monitoring dashboard later).
- Completely client-based, supports dynamically adding scheduled tasks and task listeners.
- Supports one-time tasks, fixed-rate tasks, and cron expression tasks ( using cron-utils for expression parsing).
<dependency>
<groupId>top.rows.cloud.owl.job</groupId>
<artifactId>owl-job-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>top.rows.cloud.owl.job</groupId>
<artifactId>owl-job-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
//全局配置
OwlJobConfig timedConfig = new OwlJobConfig()
.setNamespace("owl-job")
.setExecutorThreadPool(
new OwlJobConfig.ThreadPoolProperties()
.setThreadNamePrefix("TJ")
.setCorePoolSize(50)
.setMaxPoolSize(100)
.setQueueCapacity(2000)
);
IOwlJobExecutor executor = new OwlJobExecutor(timedConfig);
IOwlJobTemplate template = new OwlJobTemplate(timedConfig, RedissonClientGetter.get(), executor);
template.init();
// Task group
String group = "hello-owl-job";
executor.addListener(group, param ->{
System.out.println("Current time: "+LocalDateTime.now());
System.out.println("Scheduled time: "+param.getTime());
System.out.println("Data read: "+param);
});
// Add task
template.add(
group,
OwlJob.disposable(LocalDateTime.now().plusSeconds(3)) // Set initial execution time (current time plus three seconds)
.setParam("job of disposable") // Set callback parameter
);
// Sleep for three seconds to see the result
Thread.sleep(3000);
// End program; shutdown task processing
template.shutdown();
executor.addListener(
GROUP,
(param) ->System.out.println(
"\n当前时间:"+LocalDateTime.now() +
"\n设定时间:"+param.getTime() +
"\n任务参数:"+param.getParam()
)
)
OR
executor.addListener(
new IOwlJobListener<Object>() {
@Override
public String group () {
return GROUP;
}
@Override
public void run (IOwlJobParam < Object > param) {
System.out.println(
"\n当前时间:" + LocalDateTime.now() +
"\n设定时间:" + param.getTime() +
"\n任务参数:" + param.getParam()
);
}
}
);