Java:Get a value from a thread using some polling mechanism and kill the thread based on the value…?
<p>how can i poll for value from another thread. 
For eg: I have a method in ThreadA which calls a method of another Thread(ThreadB). I need to use some polling mechanism so that for every 5 seconds I should be able to check the value of return type(String) of that method and based on the value (say SUCCESS/FAILURE) i should be able to kill the ThreadB.
How can it be done.. Please help.</p>

<p>This can be done with Observer patter, but now small change -- I am polling every 5 secnds for the value of threadB. but the value of ThreadB will change only after 10 min. here my question is in every 5 seconds how can i get the value of ThreadB without invoking it everytime. ThreadB can only be invoked once.</p>
