Banking application - Optimizing java multi-threading code
This code is broken.

Imagine an Account with $100, two threads, one depositing $1, the other withdrawing $50.

Thread one acquired lock1, and begins executing:

this.balance = getBalance() + amount;


and reads $100 ...

Thread two acquired lock2, reads the balance (still $100), subtracts $50, stores the new balance ($50) and releases lock2.

... (back to thread one) ... adds $1, for a total of $101, which it stores in balance.

Free money!  The withdrawal of $50 was forgotten. 

You must lock all read-modify-write operations of an object's member with the same lock.