How do i assign Status with CallMe() using isFinish() to have returned value true?
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;
}
There are two ways of doing this.
The first is to use a future computation result and the other is to have a shared variable.
I think that the first method is much cleaner than the second, but sometimes you need to push values to the thread too.
RunnableFuture.FutureTaskimplements aRunnableFuture. So you create that task which, once executed, will have a value.You create a class holding a value and share a reference to that class. You may create your own class or simply use the
AtomicReference.By holder class, I mean a class that has a public modifiable attribute.