Em chào mọi người
Em đang làm lấy giá trị cron @Scheduled từ cơ sở dữ liệu để làm job tự động vào thời gian cố định, thời gian được lấy từ csdl em muốn hỏi là làm sao để cấu hình lấy được thời gian từ csdl đó em cảm ơn!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Nếu em sử dụng annotation kia thì không có cách nào em ạ
nếu không sử dụng annotation @Scheduled thì mình sử lí ra sao vậy anh em code spring boot
Em có thể sử dụng CronTask nhé, tham khảo: https://stackoverflow.com/questions/56938152/how-to-schedule-a-cron-job-in-spring-boot-without-using-scheduled-annotation
Bạn có thể thử đoạn này. Code này vẫn sử dụng schedule api của spring
@Configuration
@EnableScheduling
public class MyAppConfig implements SchedulingConfigurer {
@Autowired
Environment env;
@Autowired
MyService myService;
@Bean(destroyMethod = "shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(100);
}
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
taskRegistrar.addTriggerTask(
new Runnable() {
@Override public void run() {
//do something
}
},
new Trigger() {
@Override public Date nextExecutionTime(TriggerContext triggerContext) {
//Here get scheduling value from db and calculate nextExecutionTime
}
}
);
}
}