多项选择题
现有:
class Waiting implements Runnable {
boolean flag=false;
public synchronized void run() {
if (flag) {
flag=false;
System.out.print ("1");
try { this.wait(); ) catch (Exception e) { }
System.out.print ("2");
}
else {
flag=true;
System.out.print ("3");
try{Thread.sleep (2000); } catch(Exception e) {}
System.out.print ("4");
notify();
}
}
public static void main (String [] args) {
Waiting w=new Waiting();
new Thread (w) .start();
new Thread (w) .start();
}
}
以下哪两项是正确的?()
A.代码输出l 3 4
B.代码输出3 4 1
C.代码输出l 2 3 4
D.代码输出1 3 4 2
E.代码运行完毕
F.代码不会完成
相关考题
-
单项选择题
现有: 5. class Order2 implements Runnable { 6. public void run() { 7. for (int x- o; x<4; x++) { 8. try{Thread.sleep(100); )catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(string [] args) { 12. Thread t=new Thread(new order2()); 13. t.start(); 14. for(int x=0; x<4; x++) { 15. //insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm?()
A. Thread.sleep(1);
B. Thread.sleep(100);
C. Thread.sleep(1000);
D. try{ Thread.sleep(1); ) catch (Exception e) { }
E. try{Thread.sleep(100); ) catch (Exception e) { }
F. try{Thread.sleep(1000); ) catch (Exception e) { } -
单项选择题
现有: class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(Stri_ng [] args) { new Thread (new ThreadExcept()).start(); try { int x=Integer.parselnt (args [0]); Thread. sleep (x); System.out.print("main"); } catch (Exception e) { } } } 和命令行: java ThreadExcept l000 哪一个是结果?()
A.main
B.编译失败
C.main java.lang.RuntimeException: exception
D.代码运行,但没有输出 -
单项选择题
现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下: public void run() { System.out.print ("go"); } 及: t.start(); t.start(); t.run(); 哪一个是结果?()
A.go go
B.go go go
C.go之后跟着一个异常
D.go go之后跟着一个异常
