java中synchronized块是怎么用的给个例子

以下两个例子说明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();。。。。。。。。。。。。。。。。。

详情请进:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner6_web.html#Usage

阅读更多

没有更多推荐了,返回首页