there are two threads in your scenario, the main, and the child. the main thread halts at the point you call join() and waits for the child thread to finish (return from its run() method).

if the child thread is still working when the timeout expires, the main thread issues an interrupt() to it, and the child thread (if it is blocked, which it ought to be) will stop what it is doing, unblock, and receive an InterruptedException

it is at this stage in your run() method, that you would handle the receipt of an InterruptedException, set some class variable to the answer, or null if there was no answer, and then return from run

immediately after the join the main thread should check the child thread for the answer. it can also check the thread for being isInterrupted() which will give you a true or false indicating if the thread was interrupted or not.. this is probably a moot point though, because if youre setting an answer to null if there was no answer due to interruption, then you dont need to check for isInterrupted() as the answer implies the thread was interrupted. If however, null is a valid answer and cannot be relied upon to imply interruption, then isInterrupted() might be of some use

after the child thread has returned from its run() it will do no more work unless it is started again. you may wish to pool it, or you can just get rid of it by setting the thread object to null and waiting for the garbage collector to eat it..


thread stopping and killing is not a good idea, and usually unnecessary because in nearly all cases, it is possible to have a thread exit from its run() method whether it finished its work or not. as there is only one exit point, that can be made to pass through a finally{} block, you can control the amount of mess the thread leaves behind (i.e. it shouldnt)
in your code, your isAlive() check is unnecessary.. you should simply check whether the thread delivered an answer or not, then dispose of it via usual java garbage collection. it would be the child thread's resposibility to close network conenctions etc that it had made