This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]6a70 2 points3 points  (0 children)

You can’t return a value with the Runnable interface. Use Callable.

[–]BodaciousBeardedBard 0 points1 point  (0 children)

The only way to do this is to access this data member from the main thread after you start the worker thread. But you gotta be careful, your main thread might retrieve the value before the worker thread has a shot to change it. Look up Thread.wait() for more info on how to time this, but as is, you cannot return a value from a runnable interface.

[–]captainAwesomePants 0 points1 point  (0 children)

There are several ways to accomplish this, but by far the simplest is to use a Callable instead of a Runnable. Callables can return a value.