题目内容

下面的程序编译运行后输出的结果是( )。public class A implements Runnable {public static void main(String argv[]) {A a = new A();Thread t = new Thread(a);t.start();}public void run() {while(true) {try{Thread.currentThread().sleep(1000);}catch(InterruptedException e){System.out.println(e.toString());}System.out.println("looping while");}}}

A. 在屏幕上重复输出 "looping while"。
B. 在屏幕上输出一次 "looping while"。
C. 没有结果输出。
D. 出现编译错误。

查看答案
更多问题

对于线程的生命周期,下面四种说法正确的有哪些? (多选)()

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个阶段,分别是________、________、________、阻塞状态和死亡状态。

答案查题题库