If I understand the problem, your process is linear - so if at some point a piece of code gets 'stuck', and that is beyond your control (for example a 3rd party library or a Runtime.exec() call), then you should split your process up to run parallel using more than a single thread. For example, you could start a Timer, kickoff the process, and monitor completion of the process using a boolean flag. When the timer fires it checks if if the flag has been set (task completed) or not (incomplete) and acts accordingly. To learn more about threads, see
Lesson: Concurrency (The Java™ Tutorials > Essential Classes)