Take the 2-minute tour ×  Say I've got something like this
public void run(){     Thread behaviourThread = new
Thread(abstractBehaviours[i]);  And I want to wait until
abstractBehaviours[i] run method has either finished or run for
5000 milliseconds. How do I do that? behaviourThread.join(5000)
doesn't seem to do that afaik (something is wrong with my code
and I've put it down to that).  All the abstract
abstractBehaviour class is of course Runnable. I don't want to
implement it inside each run method as that seems ugly and there
are many different behaviours, I'd much rather have it in the
calling/executing thread and do it just once.  Solutions? First
time doing something as threaded as this. Thanks!  edit: So the
interrupting solution would be ideal (requiring minimal changes
to AbstractBehaviour implementations). BUT I need the thread to
stop if it has finished OR 5000 milliseconds have passed so
something like the following would not work because the thread
may finish before the while loop in the parent