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 ..它仍然能够运行并在控制台上打印其详细信息。需要对此进行解释
最佳答案
Thread instance t is initialized to null
不,线程
变量 设置为空值。变量不是实例 - 值得绝对确保您理解这一点。
更改变量的值根本不会影响现有的 Thread
对象。
关于java - java中线程初始化为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655265/