package thread;
public class th {
public static int j = 0;
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
t tt = new t();
tt.start();
th.xun();
System.out.println("线程1");
d dd = new d(); dd.start();
}
}
public static synchronized void xun()
{
for (int i = 0; i < 5; i++) {
th.j++;
System.out.println(j);
}
}
}
class t extends Thread{ public void run() {
th.xun();
System.out.println("线程2");
super.run();
}
}
class d extends Thread{ public void run() {
th.xun();
System.out.println("线程3");
super.run();
}
}
时间: 2024-10-18 10:33:07