title: How to handle multithreading in simple cash deposit withdraw program
body: <p>My instructor said to use multi-threading for update an account management system. Given below is a rough idea of the system.
  <img src="https://i.stack.imgur.com/Z5vBv.png" alt="enter image description here"></p>
  
  <p>Here is my source code for it. </p>
  
  <p><strong>Account class</strong></p>
  
  <pre><code>public class Account {
      int balance= 1000;
  
      public int getBal(){
          return balance;
      }
  
      public void withdraw(int bal){
          balance= balance-bal;
      }
  
      public void deposit(int bal){
          balance= balance+bal;
      }
  }
  </code></pre>
  
  <p><strong>ThreadExercise class</strong></p>
  
  <pre><code>public class ThreadExercise implements Runnable{
  
      Account acc = new Account();
  
      public static void main(String[] args) {
          ThreadExercise ts = new ThreadExercise();
          Thread t1 = new Thread(ts, "person 1");
          Thread t2 = new Thread(ts, "person 2");
          Thread t3 = new Thread(ts, "person 3");
          t1.start();
          t2.start();
          t3.start();
      }
  
      @Override
      public void run() {
          for (int i = 0; i &lt; 3; i++) {
              makeWithdraw(100);
              if (acc.getBal() &lt; 0) {
                  System.out.println("account is overdrawn!");
              }
              deposit(200);
          }
      }
  
  
      private synchronized void makeWithdraw(int bal){
          if (acc.getBal()&gt;=bal) {
              System.out.println(Thread.currentThread().getName()+" "+ "is try to withdraw");
              try {
                  Thread.sleep(100);
              } catch (Exception e) {
                  e.printStackTrace();
              }
              acc.withdraw(bal);
              System.out.println(Thread.currentThread().getName()+" "+ "is complete the withdraw");
          }else{        
              System.out.println(Thread.currentThread().getName()+ " "+"doesn't have enough money for withdraw ");
          }
      }
  
      private synchronized void deposit(int bal){
          if (bal&gt;0) {
              System.out.println(Thread.currentThread().getName()+" "+ " is try to deposit");
              try {
                  Thread.sleep(100);
              } catch (Exception e) {
                  e.printStackTrace();
              }
              acc.deposit(bal);
              System.out.println(Thread.currentThread().getName()+" "+ "is complete the deposit");
          }else{        
              System.out.println(Thread.currentThread().getName()+ " "+"doesn't have enough money for deposit");
          }
      }
  }
  </code></pre>
  
  <p>Code is working fine. But I really think something is missing this code. Can you please help me for finding that fault.  </p>
  
  <p><br/>
  Is it not be enough synchronizing the makeWithdraw() and deposit() methods in ThreadExercise class and should I remove that synchronizing and synchronize the withdraw() and deposit() in Account class. Please give me a clear idea. 
  <br/>
  Thank you for your support. </p>