如何將Status
與CallMe()
一起使用isFinish()
返回值爲true?如何從Java的內部線程Runnable方法獲取返回值?
public static boolean isFinish()
{
boolean Status = false;
new Thread(new Runnable()
{
public void run()
{
/* This shell return true or false
* How do you keep it in Status
*/
CallMe();
}
}).start();
/* How can i get the true or false exactly from CallMe? here */
return Status;
}
public static boolean CallMe()
{
/* some heavy loads ... */
return true;
}
爲什麼使用線程? start()將創建一個單獨的執行線程,此時isFinish將繼續執行。 –