I want to run a thread for some fixed amount of time. If it is not completed within that time, I want to either kill it, throw some exception, or handle it in some way. How
Consider using an instance of ExecutorService. Both invokeAll()
and invokeAny()
methods are available with a timeout
parameter.
The current thread will block until the method completes (not sure if this is desirable) either because the task(s) completed normally or the timeout was reached. You can inspect the returned Future
(s) to determine what happened.