public class Test {
public static synchronized void main(String[] args) {
Thread t=new Thread(){
@Override
public void run() {
super.run();
hello();
}
};
System.out.println("run");
t.run();//t.start();
}
public static void hello(){
System.out.println("hello");
}
}
当t调用后run()时,被当作一种普通的方法调用,在执行run()方法的过程中,在输出语句前有一个hello()所以先输出hello换行输出run;但t调用start()时开启了一个线程,与此同时main线程获得了Test.class对象的资源锁,输出run后释放锁资源,t线程获得锁资源具备运行资格后,输出hello。