Spring Boot Scheduler | Spring Job Scheduler | @Scheduled Annotation | Async Scheduler
HTML-код
- Опубликовано: 10 сен 2024
- In this video, I will explain how the Spring @Scheduled annotation can be used to configure and schedule tasks and will explain about fixed rate, fixed delay, async scheduler and task scheduler.
My Top Playlists:
Spring Boot with Angular : • Spring Boot + Angular
Spring Boot with Docker & Docker Compose : • Spring Boot Docker & D...
Spring Boot with Kubernetes : • Spring Boot Docker Kub...
Spring Boot with AWS : • Spring Boot + AWS
Spring Boot with Azure : • Spring Boot Azure
Spring Data with Redis : • Spring Data with Redis
Spring Boot with Apache Kafka : • Apache kafka
Spring Boot with Resilience4J : • SpringBoot Resilience4j
It's great to see you back sir . Thank you for such amazing content 🎉🎉
How to schedule a task as per the end user request (like based on strat date or end date) using api call in springboot. Could you please make a video for that....It will be very useful
Is there a way schedule a job and run to pull data from storage only once even when running on multiple instances? So it won’t pull same record twice before my update back to storage.
Sir, your videos are very helpful. Request you to please upload more videos.
Thank you, I will
Very well explained, thanks a lot for the hard work and sharing your knowledge.
Glad it was helpful!
Can we use fixedRateString with minutes also and if so, then how to define that in this?
very helpful sir
Hi sir, how to get the server ip address when @cron is running in utility, i have used httpservlet request, but i am getting an exception
Send me an exception stack trace
Is there any way to schedule a job once not with postConstruct?
Very useful and informative. How to make jobs synchronous when application instance running on multiple nodes?
You might encounter scenarios where you want to ensure that a scheduled job is executed only once, regardless of the number of nodes. To achieve this, you can use a distributed locking mechanism. One popular approach is to use a distributed lock manager like Apache ZooKeeper or Redis.
@Component
public class ScheduledTask {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RedisScript distributedLockScript;
@Scheduled(cron = "0 0 1 * * ?") // Example cron expression
public void scheduledJob() {
String lockKey = "your-lock-key";
String lockValue = "unique-value";
// Attempt to acquire the lock
Boolean lockAcquired = redisTemplate.execute(distributedLockScript, Collections.singletonList(lockKey), lockValue);
if (lockAcquired != null && lockAcquired) {
try {
// Your scheduled job logic goes here
} finally {
// Release the lock when the job is done
redisTemplate.delete(lockKey);
}
} else {
// Another node already acquired the lock, skip this execution
}
}
}
Please refer the below link as well
stackoverflow.com/questions/31288810/spring-scheduled-task-running-in-clustered-environment
Great video!
Can you tell me how I could read this cron expression from a docker-compose?
for some reason my fixedrate is also stopping for 2 seconds because of thread sleep despite having fixedrate value set to 1000 only
Edit: never mind, i got it! so fixed rate does not have to work according to the given time to it! instead it only takes out that time out of the tread sleep so like if we give 3 sec to fixed rather and thread sleep is on 5 sec thenmethod will run each 2 sec because 3 out of 5 is 2
LIKE LIKE LIKE LIKE
ᑭяỖmo??