2012-07-18 37 views
-6

我在面試中遇到以下問題:什麼是主題類的靜態和本機方法

什麼是Thread類的靜態和本機方法?

  1. yield
  2. start
  3. join
  4. wait

我瞭解多線程的概念,例如:

Thread t = new Thread(); 
t.start(); // Thread starting execution 
t.join(); // (or t.wait()) thread state will go to waiting 

但是我沒有回答在帖子開頭提到的面試問題。

+2

我不明白爲什麼面試官會問什麼是本地方法。這是依賴於實現的,非本地方法也可以稱爲本地方法... – 2012-07-18 12:46:49

+0

面試問題,測試你的記憶關於具體apis或實現細節是你的知識測試很差。 – 2012-07-18 21:21:30

回答

2

請參閱Java線程文檔。

http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html

方法如currentThread()sleep etc..在本質上吃static

有幾種方法,如currentThreadisAlive等都是native

請參閱this

yield -> public static native void 
start -> public synchronized void start 
join -> public final synchronized void 
wait -> In object class 
+0

感謝您的回答 – Ashok 2012-07-18 13:08:25

+0

@amicngh sir,native是什麼意思?你能用實例來解釋一下嗎? – SKR 2012-07-18 13:24:36

+0

@SKR:通過http://www.javaworld.com/javatips/jw-javatip23.html – amicngh 2012-07-18 13:26:30

0

您可能想要查看java.lang.Thread的Javadoc。它本質上是告訴你:

  1. yield()static
  2. wait()static,並從java.lang.Object
  3. startjoin繼承不static,並由java.lang.Thread類中定義。

native內斯的這些方法很可能VM實現相關的,但它一定程度上取決於什麼的問題實際上是由native手段。

相關問題