Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1.     private static class Account {
  2.         Lock mylock = new ReentrantLock();
  3.         private int balance = 0;
  4.  
  5.         public int getBalance() {
  6.             return balance;
  7.         }
  8.  
  9.         public void deposit(int amount) {
  10.             mylock.lock();
  11.             try {
  12.                 int newBalance = balance + amount;
  13.         //        try {
  14.         //            Thread.sleep(1); // Muuttele parametria
  15.         //        } catch (InterruptedException ex) {
  16.         //        }
  17.                 balance = newBalance;
  18.             } finally {
  19.                 mylock.unlock();
  20.             }
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement