以下兩個例子說明synchronized塊的用法: (視頻下載) (全部書籍)例1.9.4_a-本章源碼class A { public void disp() { System.out.println("新線程馬克-to-win啟動:"); for (int i = 0; i < 10; i++) ...
以下兩個例子說明synchronized塊的用法: (視頻下載) (全部書籍)
例1.9.4_a-本章源碼
class A {
public void disp() {
System.out.println("新線程馬克-to-win啟動:");
for (int i = 0; i < 10; i++) {
System.out.println(i);
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
}
public class TestMark_to_win extends Thread {
A a;
public TestMark_to_win(A a) {
this.a = a;
}
public void run() {
a.disp();
}
public static void main(String[] args) {
A a = new A();
TestMark_to_win t1 = new TestMark_to_win(a);
TestMark_to_win t2 = new TestMark_to_win(a);
。。。。。。。。。。。。。。。。。