日期:2014-05-20 浏览次数:20658 次
public class Test4 { public static void main(String[] args) { computer4 c1 = new computer4('a'); computer4 c2 = new computer4('b'); c1.start(); c2.start(); } } class computer4 extends Thread { char ch; Object obj = new Object(); computer4(char ch) { this.ch = ch; } public void print(char ch) { for (int i = 0; i < 10; i++) { System.out.print(ch); } } public void run() { synchronized (obj) { print(this.ch); System.out.println(); } } }
synchronized (computer4.class)
------解决方案--------------------
Object obj = new Object();