SCJP題庫第243題
Given that Triangle implements Runnable, and:
31. void go() throws Exception{
32. Thread t = new Thread(new Triangle());
33. t.start();
34. for(int x=1; x<100000; x++){
35. //insert code here
36. if(x%100 == 0) System.out.print("g");
37. }}
38. public void run(){
39. try{
40. for(int x=1; x<100000; x++){
41. //insert the same code here
42. if(x%100 == 0) System.out.print("t");
43. }
44. }catch(Exception e){}
45.}
Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute? (Choose two.)
A. Thread.wait();
B. Thread.join();
C. Thread.yield();
D. Thread.sleep(1);
E. Thread.notify();
Ans: CD
解說:在第35行和41行插入那二個程式敘述,可以使得二條執行暫時性地停止並允許其他執行緖可以執行?
yield的退讓的意思,一旦下yield,立刻退出CPU,進入runable狀態。
sleep是睡眠一段時間(也是離開CPU,但確保多少時間後才能進runable的狀態).。
Comments