【发布时间】:2012-05-26 04:24:19
【问题描述】:
public class ThreadState {
public static void main(String[] args){
Thread t = new Thread(){
public void run(){
// infinite loop
while (true) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}
System.out.println("thread is running..."+Thread.currentThread().toString());
}
}
};
t.start() ;
t = null ;
while (true) {
try {
Thread.sleep(3000);
}
catch (InterruptedException e) {
}
System.out.println("thread is running..."+Thread.currentThread().toString());
}
}
}
线程实例 t 被初始化为 null .. 它仍然能够运行并在控制台上打印其详细信息。需要解释一下
【问题讨论】:
-
这行
t = null;会不会有什么关系? -
您在启动后将其设置为 null。有什么问题?
-
我认为 t = null 应该会影响线程执行。由于线程没有引用,它应该给出一些例外..这就是我的怀疑所在。如果你认为我错了,你可以让我理解
标签: java multithreading