场景
比如flink中定期后台更新小维表到内存中
package test
import java.util.concurrent.{Executors, TimeUnit}
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
object Schedular {
val logprefix = "[LogPrefix]"
def getCurrentTime(): String = {
val now = LocalDateTime.now()
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
now.format(formatter)
}
def main(args: Array[String]): Unit = {
val scheduler = Executors.newScheduledThreadPool(2) //和任务数一致,可以不用排队执行
try {
// 设置定时调度
scheduler.scheduleAtFixedRate(() => {
try {
println(s"${getCurrentTime()} - Scheduled task is running job1")
} catch {
case e: Exception =>
printl