日期:2014-05-20 浏览次数:20753 次
public class TT implements Runnable{ int b = 100; public synchronized void run(){ try { modify_1(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public synchronized void modify_1() throws InterruptedException{ b=1000; Thread.sleep(5000); System.out.println(b); } public synchronized void modify_2() throws InterruptedException{ Thread.sleep(2500); b=2000; System.out.println(b); } public static void main(String[] args) throws InterruptedException { TT tt = new TT(); Thread th = new Thread(tt); th.start(); tt.modify_2(); System.out.println(tt.b); } }