package net.oschina.concurrency.syncnew;

/**
 * 
 * @author zdc52 添加同步保护
 */
public class Account {

	private double balance;

	public double getBalance() {
		return balance;
	}

	/**
	 * 
	 * 
	 *
	 *        
	 */
	public void setBalance(double balance) {
		this.balance = balance;
	}

	/**
	 * 
	 * 
	 * 
	 * 
	 */
	public synchronized void addAmount(double amount) {
		double tmp = balance;
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		tmp += amount;
		balance = tmp;
	}

	/**
	 * 
	 * 
	 * 同步保护
	 * 
	 */
	public synchronized void subtractAmount(double amount) {
		double tmp = balance;
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		tmp -= amount;
		balance = tmp;
	}

}

@@ -58,14 +58,14 @@
 hor 
-zdc52 
+%E5%BC%A0%E5%A4%A7%E5%B7%9D%0A *
 %E6%B7%BB%E5%8A%A0%E5%90%8C%E6%AD%A5
@@ -292,32 +292,36 @@
 *%0A%09 * %0A%09 * %0A%09 * 
+%E5%90%8C%E6%AD%A5%E4%BF%9D%E6%8A%A4
 %0A%09 * %0A%09 */%0A%09publ

Update Account.java