本帖最后由 littlefoxtail 于 2013-5-13 16:10 编辑
- class House{
-
- }
- class Man extends Thread{
-
- House h;
- public Man(House h){
- this.h = h;
- }
- public void run() {
- synchronized (h) {
- System.out.println("买房子");
- }
- }
- }
- public class DeadLockDemo {
- public static void main(String[] args) {
-
- House h = new House();
- Man m = new Man(h);
- m.start();
-
- synchronized (h) {
- try {
- m.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("end");
- }
- }
- }
复制代码 这个死锁程序对么,有没有可能先执行run方法,再执行主函数 |