关于多线程读取数据库记录出现的问题
线程的run()部分如下
public void run() { System.out.println(_threadName + " starts to run."); float updatedValue = 0; try { Connection conn = DatabaseHelper.getConnection(); updatedValue = _account.getBalance() + _amount; System.out.println(_threadName + " before:" + _account.getBalance()); System.out.println(_threadName + " sleep."); Thread.sleep(_delayedTime); System.out.println(_threadName + " wake up."); System.err.println(_threadName + " 1 balance = " + _account.getBalance()); _account.setBalance(updatedValue); System.err.println(_threadName + " 2 balance = " + _account.getBalance()); System.out.println(_threadName + " after:" + _account.getBalance()); conn.commit(); conn.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println(_threadName + " stops running here."); }