Skip to content

Instantly share code, notes, and snippets.

@eaiman-shoshi
Last active August 22, 2020 17:26
Show Gist options
  • Save eaiman-shoshi/c98329e8d1502c73ddb81a6d9f4f3786 to your computer and use it in GitHub Desktop.
Save eaiman-shoshi/c98329e8d1502c73ddb81a6d9f4f3786 to your computer and use it in GitHub Desktop.
bla
package com.masterdevskills.cha1;
public class Account {
private int balance;
public Account(int balance) {
this.balance = balance;
}
public void transfer (int value, Account account) {
synchronized (account) {
synchronized (this) {
balance = balance - value;
account.deposit(value);
}
}
}
public void deposit(int value) {
balance = balance + value;
}
public static void main(String[] args) {
Account a = new Account(100);
Account b = new Account(500);
a.transfer(50, b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment