2019.4.27 class AnotherBank{ private double[] accounts; // private LongAccumulator adder = new LongAccumulator(Long:sum, 0); public static final ThreadLocal<SimpleDateFormat> dataFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); public AnotherBank(int n, double initialBalance){ accounts = new double[n]; Arrays.fill(accounts, initialBalance); } public synchronized void transfer(int from, int to, int amount) throws InterruptedException{ while(accounts[from] < amount) wait(); accounts[from] -= amount; accounts[to] += amount; notifyAll(); } public synchronized double getTotalBalance(){ double sum = 0; for(double a: accounts) sum += a; return sum; } public int size(){ return accounts.length; } }