/** * This method stops the scheduler execution. Before returning, it waits the * end of all the running tasks previously launched. Once the scheduler has * been stopped it can be started again with a start() call. * * @throws IllegalStateException * Thrown if this scheduler is not started. */ public void stop() { lock (lockObj) { if (!started) { throw new SystemException("Scheduler not started"); } // Interrupts the timer and waits for its death. timer.Interrupt(); tillThreadDies(timer.Thread); timer = null; // Interrupts any running launcher and waits for its death. for (; ;) { LauncherThread launcher = null; lock (launchers) { if (launchers.Count == 0) { break; } launcher = launchers[0]; launchers.RemoveAt(0); } launcher.Interrupt(); tillThreadDies(launcher.Thread); } launchers = null; // Interrupts any running executor and waits for its death. // Before exiting wait for all the active tasks end. for (; ;) { TaskExecutor executor = null; lock (executors) { if (executors.Count == 0) { break; } executor = executors[0]; executors.RemoveAt(0); } if (executor.CanBeStopped()) { executor.Stop(); } tillExecutorDies(executor); } executors = null; // Change the state of the object. started = false; } }
/** * This method starts the scheduler. When the scheduled is started the * supplied tasks are executed at the given moment. * * @throws IllegalStateException * Thrown if this scheduler is already started. */ public void start() { lock (lockObj) { if (started) { throw new SystemException("Scheduler already started"); } // Initializes required lists. launchers = new List <LauncherThread>(); executors = new List <TaskExecutor>(); // Starts the timer thread. timer = new TimerThread(this); timer.SetDaemon(daemon); timer.Start(); // Change the state of the scheduler. started = true; } }
/** * This method stops the scheduler execution. Before returning, it waits the * end of all the running tasks previously launched. Once the scheduler has * been stopped it can be started again with a start() call. * * @throws IllegalStateException * Thrown if this scheduler is not started. */ public void stop() { lock (lockObj) { if (!started) { throw new SystemException("Scheduler not started"); } // Interrupts the timer and waits for its death. timer.Interrupt(); tillThreadDies(timer.Thread); timer = null; // Interrupts any running launcher and waits for its death. for (; ; ) { LauncherThread launcher = null; lock (launchers) { if (launchers.Count == 0) { break; } launcher = launchers[0]; launchers.RemoveAt(0); } launcher.Interrupt(); tillThreadDies(launcher.Thread); } launchers = null; // Interrupts any running executor and waits for its death. // Before exiting wait for all the active tasks end. for (; ; ) { TaskExecutor executor = null; lock (executors) { if (executors.Count == 0) { break; } executor = executors[0]; executors.RemoveAt(0); } if (executor.CanBeStopped()) { executor.Stop(); } tillExecutorDies(executor); } executors = null; // Change the state of the object. started = false; } }
/** * This method starts the scheduler. When the scheduled is started the * supplied tasks are executed at the given moment. * * @throws IllegalStateException * Thrown if this scheduler is already started. */ public void start() { lock (lockObj) { if (started) { throw new SystemException("Scheduler already started"); } // Initializes required lists. launchers = new List<LauncherThread>(); executors = new List<TaskExecutor>(); // Starts the timer thread. timer = new TimerThread(this); timer.SetDaemon(daemon); timer.Start(); // Change the state of the scheduler. started = true; } }