Class SerialJobRunner


  • public class SerialJobRunner
    extends Object
    This class can be used to run jobs sequentially on a separate thread. A job is only started after any previous job has been completed (including notification of the listener) or the previous job has been cancelled. The thread will only run as long as there are jobs in the queue.
    • Constructor Detail

      • SerialJobRunner

        public SerialJobRunner()
    • Method Detail

      • getJobs

        public List<Job> getJobs()
        Returns all jobs that have been posted and have not yet been completed. This includes the current job and pending jobs.
        Returns:
        the jobs
      • postJob

        public void postJob​(Job job,
                            JobListener listener)
        Posts a job with priority PRIORITY_MEDIUM.
        Parameters:
        job - the job
        listener - the job listener or null
      • postJob

        public void postJob​(Job job,
                            int priority,
                            JobListener listener)
        Posts a job that will be run after previously posted jobs with the same or higher priority, but before posted jobs with lower priority.

        You may use one of the PRIORITY_* constants defined in this class. A higher number indicates a higher priority.

        Parameters:
        job - the job
        priority - the priority
        listener - the job listener or null
      • cancelJobs

        public void cancelJobs()
        Cancels all running and pending jobs.
      • cancelJobs

        public void cancelJobs​(Job... jobs)
        Cancels the specified jobs.
        Parameters:
        jobs - the jobs
      • cancelJobs

        public void cancelJobs​(List<? extends Job> jobs)
        Cancels the specified jobs.
        Parameters:
        jobs - the jobs
      • postOnNotifyThread

        protected void postOnNotifyThread​(Runnable runnable)
        Posts the specified runnable to be run on the notify thread. In Android it will run on the UI thread. This method does not wait until the runnable is completed.
        Parameters:
        runnable - the runnable
      • runOnNotifyThread

        protected void runOnNotifyThread​(Runnable runnable)
        Runs the specified runnable on the notify thread and waits until it is completed. In Android it will run on the UI thread. This method should always be called from a worker thread to avoid a deadlock.
        Parameters:
        runnable - the runnable