dev.forkhandles.time.executors.SimpleSchedulerService.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of time4k Show documentation
Show all versions of time4k Show documentation
ForkHandles Time library
package dev.forkhandles.time.executors
import java.time.Duration
import java.util.concurrent.Callable
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
/**
* This is a SimpleScheduler backed by a ScheduledExecutorService. For production use.
*/
class SimpleSchedulerService(private val executor: ScheduledExecutorService) : SimpleScheduler {
constructor(threads: Int): this(Executors.newScheduledThreadPool(threads))
override fun schedule(callable: Callable, delay: Duration): ScheduledFuture =
executor.schedule(callable, delay.toMillis(), TimeUnit.MILLISECONDS)
override fun schedule(runnable: Runnable, delay: Duration): ScheduledFuture<*> =
executor.schedule(runnable, delay.toMillis(), TimeUnit.MILLISECONDS)
override fun scheduleWithFixedDelay(
runnable: Runnable,
initialDelay: Duration,
delay: Duration
): ScheduledFuture<*> =
executor.scheduleWithFixedDelay(runnable, initialDelay.toMillis(), delay.toMillis(), TimeUnit.MILLISECONDS)
override fun scheduleAtFixedRate(runnable: Runnable, initialDelay: Duration, period: Duration): ScheduledFuture<*> =
executor.scheduleAtFixedRate(runnable, initialDelay.toMillis(), period.toMillis(), TimeUnit.MILLISECONDS)
override fun shutdown() = executor.shutdown()
override fun isShutdown(): Boolean = executor.isShutdown
override fun submit(task: Runnable): Future<*> = executor.submit(task)
override fun submit(task: Callable): Future = executor.submit(task)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy