标签:mil 方法 print 精度 精确 .so 测试程序 实例 this
java测试程序运行时间:
long startTime = System.currentTimeMillis();
FileUtils.copyDir(FileUtils.SOURCEPATH, FileUtils.DESTPATH);
long endTime = System.currentTimeMillis();
System.out.println("运行时间:" + (endTime - startTime) + "ms");
Java的延时:
Java两种延时——thread和timer
Thread:
try
{
Thread.currentThread().sleep(500);//毫秒
}
catch(Exception e){}
解释一下线程沉睡的时间。sleep()方法并不能够让程序"严格"的沉睡指定的时间。
例如当使用500作为sleep()方法的参数时,线程可能在实际被挂起500.001毫秒后才会继续运行。
当然,对于一般的应用程序来说,sleep()方法对时间控制的精度足够了。
但是如果要使用精确延时,最好使用Timer类:
Timer:
Timer timer=new Timer();//实例化Timer类
timer.schedule(new TimerTask(){
public void run(){
System.out.println("退出");
this.cancel();
}
},500);//五百毫秒
区别:
Thread.sleep延时方法只运行一次;
timer能延时多次,
使用timer.schedule(new MyTask() , 2000); 则每间隔2秒执行MyTask();
标签:mil 方法 print 精度 精确 .so 测试程序 实例 this
原文地址:http://www.cnblogs.com/alisonGavin/p/7798162.html