自己写着学习用的

public class TestThreadATM implements Runnable{
	ATM atm = new ATM();
	
	public static void main(String[] args) {
		TestThreadATM tt = new TestThreadATM();
		Thread laogong = new Thread(tt);
		Thread laopo = new Thread(tt);
		
		laogong.setName("laogong");
		laopo.setName("laopo");
		
		laogong.start();
		laopo.start();
	}
	
	@Override
	public void run() {
		atm.quQian(Thread.currentThread().getName(), 1000);
	}
	
}

class ATM{
	private static int totalMoney = 2000;
	public synchronized void quQian(String name, int money){
		totalMoney = totalMoney - money;
		System.out.println(name + "取钱:" + money);
		System.out.println("还剩余:" + totalMoney + "元 ");
	}
}