请问JAVA定时器怎么写? 刚刚开始学JAVA,不知道JAVA类似JS里面的setTimeout这样的定时器,在规定多少秒之后执行后面的代码,我现在想要一个比如5秒钟之后在控制台打印 你好然后 定时器停止 但是程序不退出 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1. java.util.Timer&TimerTask2. ScheduledExecutorService 线程睡眠:public class Test1 { public static void main(String[] args) throws Exception{ Thread.sleep(5000); System.out.println("你好!") ; //然后继续写你想写的代码 }} Timer t = new Timer();t.schedule(new TimerTask(){ public void run(){ System.out.println("hello"); }},5000); 小弟想问下 有什么工具能把java应用转换成windows程序啊? 菜鸟学习一个月了跪求谁能回答一下这个问题 求高手解一面试题! 请教一下大家java里面有没有测试某段程序的执行时间的方法 初学者求助(分】 如何让程序停留几秒再执行下面的语句? Java如何处理bmp文件,在线求解答! 问开发GUI的工具? 我的map问题,请教! 心静,才会学好程序设计,心地善良,才会成人杰! serial中的getInputString与getOutputString的具体用法。 类的实例化的小问题,在线等
2. ScheduledExecutorService
Thread.sleep(5000);
System.out.println("你好!") ;
//然后继续写你想写的代码
}
}
Timer t = new Timer();
t.schedule(new TimerTask(){
public void run(){
System.out.println("hello");
}
},5000);