You can join on a thread for some time and after the join if it still is alive, interrupt to kill it.
Your thread must be able to handle the interruption that is going to occur.
This is one of the possible ways... may be someone else will come up with some more possibilities
The current thread starts this new thread. It should not block afterwards. However, this new thread needs to be limited in time. Using join on this thread from the current thread will block the current thread. To prevent that, the current thread starts two threads:
- the timed thread
- a thread that will call join on the timed thread
Rob Prime wrote:To be honest, I come to the same conclusion.
The current thread starts this new thread. It should not block afterwards. However, this new thread needs to be limited in time. Using join on this thread from the current thread will block the current thread. To prevent that, the current thread starts two threads:
- the timed thread
- a thread that will call join on the timed thread
2 threads - thats really nice! Good one,Rob!
subject: How to make a Thread run for particular amount of Time