flink加载外部数据源
override def open(parameters: Configuration): Unit = {
logger.info(“init…”)
query()
// new Timer
val timer = new Timer(true)
// schedule is 10 second 定义了一个10秒的定时器,定时执行查询数据库的方法
timer.schedule(new TimerTask {
override def run(): Unit = {
query()
}
}, 10000, 10000)
}
或者可以使用:
scheduledExecutorService.scheduleAtFixedRate(() -> {
TASK_CONFIG_MAP.putAll(configFetch.getSnapshotTasks());
log.info(“load snapshot config={}”, TASK_CONFIG_MAP);
}, 5, 5,TimeUnit.MINUTES);
建议采用第二种方式
**可以在richfunction的open方法中,通过该方法实现。
第二个参数是延迟多少执行,第三个参数才是循环执行的。