2009年2月26日 星期四

第225題

Given:
10. Runnable r = new Runnable(){
11. public void run(){
12. try{
13. Thread.sleep(1000);
14. }catch(InterruptedException e){
15. System.out.println("interrupted");
16. }
17. System.out.println("ran");
18. }
19. };
20. Thread t = new Thread(r);
21. t.start();
22. System.out.println("started");
23. t.sleep(2000):
24. System.out.println("interrupting");
25. t.interrupt();
26. System.out.println("ended");
Assume that sleep(n) executes in exactly n milliseconds. and all other code executes in an insignificant amount of time.
Place the fragments in the output area to show the result of running this code.



答案:
Output

(no more output)
started
ran
interrupting
ended

參考:13-3 Runnable介面

---------------------------------

23. 主執行緒 睡2秒, 副執行緒稅1秒, 所以先印出ran 再印 interrupt.

沒有留言:

張貼留言