问题
Hi I have Java scheduler which run on every hour and i have 16 server instances , this will be deployed in all 16 server instances . How i can ensure that these schedulers tasks won't clash each other. We doesn't want to introduce Spring batch .
回答1:
Basically you can follow 2 approaches for that:
- Be sure every instance manages its own data (not sharing it with any other one).
- Be sure only one instance can access to the information every time.
The first point depends of your own business logic, for the second one there are some tools can help you, with an easy integration with Spring:
Quartz
Shedlock (easier than Quartz but with less functionality)
回答2:
Actually there are some ways.
you can use distributed lock(Ex: hazelcast's distributed lock).
you can use pessimistic lock in database.(Lock table for each request and set status to IN_PROGRESS)
use quartz for scheduling.(Db persistence is necessary)
来源:https://stackoverflow.com/questions/62492285/scheduler-on-multiple-server-instances