这没啥问题,但是你代码不能这么写,try catch放 while 内部去。放外边catch到异常不就退出循环了!
bigdata <1194803...@qq.com.invalid> 于2022年12月11日周日 15:12写道: > > java.lang.InterruptedException: sleep interrupted > at java.lang.Thread.sleep(Native Method) > at > com.autoai.wecloud.source.MysqlSceneSource$.run(MysqlSceneSource.scala:49) > at > org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:100) > at > org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:63) > at > org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:200) > > > > > override def run(ctx: > SourceFunction.SourceContext[util.HashMap[Integer,String]]): Unit = { > try { > while (isRunning) { > val mapResult = new util.HashMap[Integer,String]() > val rs = ps.executeQuery() > while (rs.next()) { > mapResult.put(rs.getInt(1), rs.getString(2)) > } > ctx.collect(mapResult) > println("mysql条数:"+mapResult.keySet().size()) > Thread.sleep(1000*5) //每隔30s更新一下用户的配置信息! > } > } catch { > case e: Exception => log.error(s"查询数据异常, msg = ${e.getMessage}", > e.printStackTrace()) > } > } > > bigdata > 1194803...@qq.com > > > >