scala模拟一个timer

mac2022-06-30  86

直接上代码:

package com.test.scalaw.test.demo import java.util.Date /** * 模拟一个定时timer */ object Timer { def periodicCall(s : Integer,callback:()=>Unit):Unit={ while(true){ callback() Thread.sleep(s*1000) } } def main(args: Array[String]): Unit = { //采用匿名函数调用 periodicCall(2, ()=>println("hello,world"+new Date().getSeconds)) } }

 

转载于:https://www.cnblogs.com/huzi007/p/6210149.html

最新回复(0)