62,614
社区成员
发帖
与我相关
我的任务
分享
public class Q7 extends Thread {
public synchronized void f1() {
System.out.println("f1()");
try {
sleep(2000);
} catch(InterruptedException e) {
e.printStackTrace();
}
System.out.println("after 2 second");
return;
}
public static void main(String[] args) {
//创建并运行第一个线程
new Thread() {
public void run() {
Q7 test = new Q7();
System.out.println(getName());
test.f1();
}
}.start();
//创建并运行第二个线程
new Thread() {
public void run() {
Q7 test = new Q7();
System.out.println(getName());
test.f1();
}
}.start();
}
}