Link to home
Start Free TrialLog in
Avatar of PraKash
PraKash

asked on

thread method return value

After completion of running a thread is it possible force a return method from the run and return it back to the calling class?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The calling class can call a method of a Runnable

Runnable yourClass = new YourClass();
new Thread(yourClass).start();
yourClass.join();
Object o = yourClass.getReturnValue();
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aozarov
aozarov

If you are using Java 1.5 http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html
or else you can use Doug Lee concurrent.util library (based on the same idea): http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/FutureResult.html
:-)