小编Bah*_*Man的帖子

DeadLock进程首先锁定哪一个?

考虑以下:

public class Deadlock {
static class Friend{
    private final String name;

    public Friend (String name){
        this.name = name;
    }

    public String getName(){
        return this.name;
    }


    public synchronized void bow(Friend bower){
        System.out.format("\n%S: %S has bowed to me!" , this.name, bower.getName());
        bower.bowBack(this);
    }
    public synchronized void bowBack(Friend bower) {
        System.out.format("\n%S: %S has bowed back to me!", this.name, bower.getName());
    }


}

public static void main(String[] args) {
    final Friend alf = new Friend("Alf");
    final Friend arian = new Friend("Arian");

    // Thread 1 …
Run Code Online (Sandbox Code Playgroud)

java concurrency

5
推荐指数
1
解决办法
110
查看次数

标签 统计

concurrency ×1

java ×1