public class ThreadWaitDemo2 {
Object a = new Object();
public void 写文件(String 内容) {
synchronized (a) {
System.out.println("进入写文件函数的线程:" + Thread.currentThread().getName());
try {
a.wait(100);
System.out.println("线程:" + Thread.currentThread().getName()+ " wait了0.1秒");
//==============================================================================
//为什么下面的没有执行?.........
wait(1000 * 60 * 60);
Thread.sleep(1000 * 5);
System.out.println("线程:" + Thread.currentThread().getName()+ " 休息了5秒");
//==============================================================================
} catch (Exception e) {
}
for (int i = 0; i < 内容.length(); i++)
System.out.print(内容.charAt(i));
System.out.println("\n退出写文件函数的线程:"+ Thread.currentThread().getName() + "\n");
}
}
public void 创建两个线程() {
Runnable r = new Runnable() {
public void run() {
写文件("学JAVA其实是件很容易的事,只要你用心学,花时间");
}
};
Thread 线程A = new Thread(r, "线程A");
Thread 线程B = new Thread(r, "线程B");
线程A.start();
线程B.start();
}
public static void main(String arg[]) {
ThreadWaitDemo2 demo = new ThreadWaitDemo2();
demo.创建两个线程();
}
}
上面的打//====处的语句怎么没有执行?请懂线程的详细解释一下.