com.github.dtreskunov.easyssl.Scheduler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easyssl Show documentation
Show all versions of easyssl Show documentation
EasySSL is a small library to help create Spring Boot microservices that talk to each other over HTTPS with mutual authentication
package com.github.dtreskunov.easyssl;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
class Scheduler {
private static final ScheduledExecutorService SCHEDULER = Executors.newSingleThreadScheduledExecutor(
ThreadFactoryFactory.createThreadFactory(true, Scheduler.class.getSimpleName() + " daemon"));
public static void runAndSchedule(String name, long timeout, long period, TimeUnit unit, Runnable runnable) {
if (timeout > 0) {
runnable = TimeoutUtils
.builder()
.setName(name)
.setTimeout(timeout, unit)
.wrap(runnable);
}
// ensure any initial exception isn't ignored (as would happen if thrown in the executor thread)
runnable.run();
if (period > 0) {
SCHEDULER.scheduleAtFixedRate(runnable, period, period, unit);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy