相关疑难解决方法(0)

如何在Java中同步工作

首先,这是一个示例:

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("%s: %s has bowed to me!%n", 
                    this.name, bower.getName());
            bower.bowBack(this);
        }
        public synchronized void bowBack(Friend bower) {
            System.out.format("%s: %s has bowed back to me!%n",
                    this.name, bower.getName());
        }
    }

    public static void main(String[] args) {
        final Friend alphonse = new Friend("Alphonse");
        final Friend gaston = new …
Run Code Online (Sandbox Code Playgroud)

java multithreading deadlock

15
推荐指数
1
解决办法
2148
查看次数

标签 统计

deadlock ×1

java ×1

multithreading ×1