Originally posted by Ernest Friedman-Hill:
Hi
Welcome to JavaRanch!
A thread can't "return" a value in the normal sense that a method can, but what it can do is store a value somewhere, then notify other interested threads that the value has been stored. The value can be stored in a member of your Runnable implementation, or in any other well-known location -- for example, you could pass an object to the Runnable when it is constructed, and the Runnable can call a method on that object to report the result when it is completed.
To communicate between threads -- i.e., to send the message that the value is ready -- you'd use the Object.wait() and notify() methods -- do you understand those?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Loveleen Saroya:
yes thread can return a value in java 1.5 , a new interface callable just like runnable which returns a value, but u can throw exceptions also
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Originally posted by Peter Chase:
I don't understand this. But I rarely use Java 5.0/1.5 yet, so perhaps you can help.
I see the Callable interface. However, Callable is not Runnable and Thread can still only run Runnables, even in Java 5.0, can't it?
Joanne
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi