Thread.sleep()和Thread.currentThread().sleep()区别
先看一下代码
public class Thread1 extends Thread{ @Override public void run() { try { System.out.println("Start"); //Thread.sleep(5000); Thread.currentThread().sleep(5000); System.out.println("Finished"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { Thread1 t1 = new Thread1(); t1.start();
在编译器里运行看一下,没什么区别,但是在编程规范中,“调用一个实例的静态方法,而实际上应该是调用一个类的静态方法”,所以还是用Thread.sleep()最好