title: Java MultiThreading banking application
body: <p>I have a doubt on Java MultiThreading. Suppose i am having a banking application.let us say i am having one controller like below.</p>
  
  <pre><code>public class BankAccount{
  
  private String bankaccount;
  
  private long balance;
  
  getBalance(String bankaccount){
  
  //code to get balance based on bankaccount number
  
  this.balance=value; //value is the balance i get from database
  
  }
  
  updateAccount(long value){
  
   balance=balance-value;
  
  //code to store balance in database
  }
  </code></pre>
  
  <p>Let us say i have employed above code in a spring application
  I have a scenario where for one particular account number the balance is 10000.A husband and wife are both trying to withdraw amount from the same account from 2 different ATMs. Since servers internally use Multi Threading,Synchronization is needed for the above scenario. I have following doubts</p>
  
  <p>1) will the above 2 requests create 2 different objects of BankAccount class or only one object.</p>
  
  <p>2) if it creates only 1 object how server can identify a different account number and create another object to it as updating one account number should not block updating some other account number.</p>