> When designing this, if you would, give some though about different
> models for allowing a build to be stopped before completion. This
> includes the case where there is only one thread executing the build
> as well as the multi-thread case.

Threads should allways be stopped with Thread.interrupt(). I my self then
will handle the interruption as good as possible. According to the book
"Concurrent Programmin in Java" written by Doug Lea you could try :

class Terminator {

        // Try to kill; return true if known to be dead

        static boolean terminate(Thread t, long maxWaitToDie) {
                if (!t.isAlive()) return true; // already dead
                // phase 1 -- graceful cancellation
                t.interrupt();
                try {
                        t.join(maxWaitToDie);
                }
                catch(InetrruptException e {
                }
                if (!t.isAlive()) return true; // success

                // phase 2 -- trap all security checks

                theSecurityMgr.denyAllChecksFor(t);
                try

                        t.join(maxWaitToDie);
                }
                catch(InetrruptException e {
                }
                if (!t.isAlive()) return true;

                // phase 3 -- minimize damage

                t.setPriority(Thread.MIN_PRIORITY);
                return false;
        }
}

Regards
Thomas

Reply via email to