[問題] SCJP 6 題庫 243

看板java作者 (裝配匠)時間10年前 (2014/10/04 00:18), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
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(); 答案是C/D 但想問B的join不是也會讓目前running的執行緒進入Block狀態嗎? 為何不選呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.227.82.87 ※ 文章網址: http://www.ptt.cc/bbs/java/M.1412353106.A.FF8.html

10/04 01:20, , 1F
因為join()不是static method
10/04 01:20, 1F
文章代碼(AID): #1KBinI_u (java)
文章代碼(AID): #1KBinI_u (java)