题目内容

下列程序运行结果。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类中的________方法用于开户一个新线程,当新线程启动后,系统会自动调用________方法。

Thread类有3个线程优先级的常量:Thread.MIN_PRIORITY=1;Thread.MAX_PRIORITY= 10;Thread.NORM_PRIORITY= 。

答案查题题库