timeandspaceio / cronscheduler Goto Github PK
View Code? Open in Web Editor NEWAn alternative to ScheduledThreadPoolExecutor proof against the clock drift problem
License: Apache License 2.0
An alternative to ScheduledThreadPoolExecutor proof against the clock drift problem
License: Apache License 2.0
Below code :
private CronScheduler getCronSchedulerExecutor() {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat("merged-config-%d")
.setDaemon(true)
.build();
Duration syncPeriod = Duration.ofMillis(30_000L);
CronSchedulerBuilder cronSchedulerBuilder = CronScheduler.newBuilder(syncPeriod);
cronSchedulerBuilder.setThreadFactory(threadFactory);
cronSchedulerBuilder.setThreadName("merged-config-refresher");
return cronSchedulerBuilder.build();
}
cronScheduler.scheduleAtFixedRateSkippingToLatest(1000, 1800, TimeUnit.MILLISECONDS, runTimeMillis -> {
runJob(); // some execution
});
I change the time to 1 hour past and it suddenly spikes the cpu after 30 secs (maybe because my syncPeriod is set to 30secs).
May I know where I am doing wrong ?
~Thanks
Should provide a parser and docs for using standard cron expressions.
Trying to schedule a task to turn on at midnight on Thursday local time (and repeat weekly):
LocalDateTime now = LocalDateTime.now();
Duration syncPeriod = Duration.ofMinutes(1);
LocalDateTime thursdayAtMidnight = now.with(TemporalAdjusters.next(DayOfWeek.THURSDAY));
long timeBetweenServerStartAndThursday = ChronoUnit.DAYS.between(now, thursdayAtMidnight);
CronScheduler turnOnCron = CronScheduler.create(syncPeriod);
turnOnCron.scheduleAtFixedRateSkippingToLatest(timeBetweenServerStartAndThursday, 7, TimeUnit.DAYS, runTimeMillis -> {
//Do action
});
Am I doing something wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.