/** * 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 is called by a launcher thread to notify that the execution * is completed. * * @param launcher * The launcher which has completed its task. */ internal void notifyLauncherCompleted(LauncherThread launcher) { if (launcher == null) { throw new ArgumentNullException("launcher", "launcher is null."); } lock (launchers) { launchers.Remove(launcher); } }
// -- PACKAGE RESERVED METHODS -------------------------------------------- /** * Starts a launcher thread. * * @param referenceTimeInMillis * Reference time in millis for the launcher. * @return The spawned launcher. */ internal LauncherThread spawnLauncher(long referenceTimeInMillis) { ITaskCollector[] nowCollectors; lock (collectors) { nowCollectors = collectors.ToArray(); } LauncherThread l = new LauncherThread(this, nowCollectors, referenceTimeInMillis); lock (launchers) { launchers.Add(l); } l.setDaemon(daemon); l.Start(); return(l); }
/** * This method is called by a launcher thread to notify that the execution * is completed. * * @param launcher * The launcher which has completed its task. */ internal void notifyLauncherCompleted(LauncherThread launcher) { if (launcher == null) throw new ArgumentNullException("launcher", "launcher is null."); lock (launchers) { launchers.Remove(launcher); } }
// -- PACKAGE RESERVED METHODS -------------------------------------------- /** * Starts a launcher thread. * * @param referenceTimeInMillis * Reference time in millis for the launcher. * @return The spawned launcher. */ internal LauncherThread spawnLauncher(long referenceTimeInMillis) { ITaskCollector[] nowCollectors; lock (collectors) { nowCollectors = collectors.ToArray(); } LauncherThread l = new LauncherThread(this, nowCollectors, referenceTimeInMillis); lock (launchers) { launchers.Add(l); } l.setDaemon(daemon); l.Start(); return l; }