Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static class Account {
- Lock mylock = new ReentrantLock();
- private int balance = 0;
- public int getBalance() {
- return balance;
- }
- public void deposit(int amount) {
- mylock.lock();
- try {
- int newBalance = balance + amount;
- // try {
- // Thread.sleep(1); // Muuttele parametria
- // } catch (InterruptedException ex) {
- // }
- balance = newBalance;
- } finally {
- mylock.unlock();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement