看代码
public class RunnableThread implements Runnable {
public void run() {
while (true) {
System.out.println("In RunnableThread");
}
}
}public class RealRun { public void mainThread() throws Exception {
RunnableThread rt = new RunnableThread();
Thread xxx = new Thread(rt, "creating");
xxx.start();
System.out.println("in mainThread");
xxx.sleep(10000);//?????? 这里究竟是xxx线程, 还是main线程在睡觉啊????? } public static void main(String[] args) throws Exception {
RealRun rr = new RealRun();
rr.mainThread();
}}
注释的部分,究竟是xxx线程,还是main线程在sleep啊???搞不明白,因为sleep是个static方法,API文档说是“当前运行的线程sleep”,按这个说法,应该是main线程在睡觉吧试了好几次,好像也是main线程在睡觉。是这样嘛???大家给个答复
谢谢各位:)
public class RunnableThread implements Runnable {
public void run() {
while (true) {
System.out.println("In RunnableThread");
}
}
}public class RealRun { public void mainThread() throws Exception {
RunnableThread rt = new RunnableThread();
Thread xxx = new Thread(rt, "creating");
xxx.start();
System.out.println("in mainThread");
xxx.sleep(10000);//?????? 这里究竟是xxx线程, 还是main线程在睡觉啊????? } public static void main(String[] args) throws Exception {
RealRun rr = new RealRun();
rr.mainThread();
}}
注释的部分,究竟是xxx线程,还是main线程在sleep啊???搞不明白,因为sleep是个static方法,API文档说是“当前运行的线程sleep”,按这个说法,应该是main线程在睡觉吧试了好几次,好像也是main线程在睡觉。是这样嘛???大家给个答复
谢谢各位:)
解决方案 »
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver问题
- 下面的数组定义,分配在堆还是栈中?
- 50分求:eclipse+weblogic+lomboz配置图解或详细教程
- 关于java动态数组的困惑
- 怎样使JFrame一直在程序窗口的最前面 ? 急
- 线程问题,请高手指教。
- JBuilder中Integer q;Integer quantity;setQuantity(q-quantity);提示错误:
- 深圳的夜景好漂亮,我却在苦读JAVA,呵呵。
- 学java,考证意义大吗?
- 初学者的提问:关于JDK1.1.8的使用再次请教。
- JTree的节点显示
- 关于addNotify?
谢谢回复,试出来了,就是main在睡觉是这样试出来的,currentThread也是个static方法。语句xxx.currentThread()则得到的是main线程,所以xxx.sleep(10),也肯定是main线程在睡觉了谢谢maquan('ma:kju),我还以为因为没有分,没有人回复呢。呵呵