62,615
社区成员
发帖
与我相关
我的任务
分享
public void run(){
try{
for(int i = 15;i > 0;i--){
System.out.println(name + ": " + i);
Thread.sleep(200);
synchronized(this){ // 这里的synchronized(this)是指对象调用run()方法,还是wait()方法?
while(suspendFlag){
wait();
}
}
}
}
public void run()
{
synchronized(target){
target.call(msg); // 这里的synchronized(target)
// 是target对象调用call()方法,对吧
}
}
public class Thread1 implements Runnable {
public void run() {
synchronized (this) { // 这里的synchronized (this)是ta、tb分别调用run()方法?
for (int i = 0; i < 5; i++) {
System.out.println(Thread.currentThread().getName() + " synchronized loop " + i);
}
}
}
public static void main(String[] args) {
Thread1 t1 = new Thread1();
Thread ta = new Thread(t1, "A");
Thread tb = new Thread(t1, "B");
ta.start();
tb.start();
}
}