CS4j (Cron Scheduler for Java) - is a small Cron style task scheduler for Java compatible with Spring version.
<dependency>
<groupId>com.github.cs4j</groupId>
<artifactId>cs4j</artifactId>
<version>1.1.1</version>
</dependency
// Create scheduler with a pool of 10 threads with 1 second initial delay and 3 seconds check interval.
// The name of the scheduler thread will be set to 'T1'
Scheduler scheduler = new Scheduler(Executors.newFixedThreadPool(10), 1, 3, TimeUnit.SECONDS, "T1") ;
// get service instance. This can be any Java object with @Scheduled methods.
Service service = ...;
// enable scheduling for all methods with @Scheduled annotation
scheduler.schedule(service);
...
scheduler.shutdown(); // shutdown the scheduler.
Example of Service class:
public class Service {
// Cron format: second, minute, hour, day, month, day of the week
// The method runs every first second each minute
@Scheduled(cron = "1 * * * * * *")
void ping() {
log.info("pong")
}
}
The scheduler is based on Spring's CronSequenceGenerator class. It uses compatible syntax, inherits and successfully passes all original Spring tests.
The package is recommended when you can't use original Spring implementation for some reason. CS4J has no additional runtime dependencies and it's JAR file size is about 11kb.
Java 7+
Apache License 2.0
- mjdbc - small and efficient JDBC wrapper
- μotto - plain Java version of Otto Event Bus with no dependencies