对于线程的生命周期,下面四种说法正确的有哪些? (多选)()
A. 调用了线程的start()方法,该线程就进入运行状态
B. 线程的run()方法运行结束或被未catch的InterruptedException 等异常终结,那么该线程进入死亡状态
C. 线程进入死亡状态,但是该线程对象仍然是一个Thread对象,在没有被垃圾回收器回收之前仍可以像引用其他对象一样引用它
D. 线程进入死亡状态后,调用它的start()方法仍然可以重新启动
查看答案
下列程序运行结果。public class E {public static void main(String args[]) {Target target =new Target();Thread thread1 =new Thread(target);Thread thread2 =new Thread(target);thread1.start();try{ Thread.sleep(1000);}catch(Exception exp){}thread2.start();}}class Target implements Runnable{int i = 0;public void run() {i++;System.out.println("i="+i);}}
下面程序运行的结果是 。public class E {public static void main(String args[]) {Bank b=new Bank();b.thread1.start();b.thread2.start();}}class Bank implements Runnable {Thread thread1,thread2;Bank() {thread1=new Thread(this);thread2=new Thread(this);thread1.setName("A");thread2.setName("B");}public void run() {printMess();}public void printMess() {synchronized(this) { //当一个线程使用同步块时,其他线程必须等待System.out.println(Thread.currentThread().getName()+"正在使用这个方法");try { Thread.sleep(2000);}catch(Exception exp){}System.out.println(Thread.currentThread().getName()+"正在使用这个同步块");}}}
线程的整个生命周期分为5个阶段,分别是________、________、________、阻塞状态和死亡状态。
Thread类中的________方法用于开户一个新线程,当新线程启动后,系统会自动调用________方法。