/** * Attempts to immediately start a given job. Returns true if the job was * successfully started, and false if it could not be started immediately * due to a currently running job with a conflicting rule. Listeners will never * be notified of jobs that are run in this way. */ protected boolean runNow(InternalJob job) { synchronized (lock) { //cannot start if there is a conflicting job if (findBlockingJob(job) != null) return false; changeState(job, Job.RUNNING); job.setProgressMonitor(new NullProgressMonitor()); job.run(null); } return true; }
private InternalJob doRunNow(ThreadJob job, boolean releaseWaiting) { InternalJob blocking = findBlockingJob(job); //cannot start if there is a conflicting job if (blocking == null) { changeState(job, Job.RUNNING); ((InternalJob) job).setProgressMonitor(new NullProgressMonitor()); job.run(null); if (releaseWaiting) { // atomically release waiting implicitJobs.removeWaiting(job); } } return blocking; }
private InternalJob doRunNow(ThreadJob job, boolean releaseWaiting) { InternalJob blocking = findBlockingJob(job); //cannot start if there is a conflicting job if (blocking == null) { changeState(job, Job.RUNNING); ((InternalJob) job).setProgressMonitor(new NullProgressMonitor()); job.run(null); if (releaseWaiting) { // atomically release waiting implicitJobs.removeWaiting(job); } } return blocking; }
private InternalJob doRunNow(ThreadJob job, boolean releaseWaiting) { InternalJob blocking = findBlockingJob(job); //cannot start if there is a conflicting job if (blocking == null) { changeState(job, Job.RUNNING); ((InternalJob) job).setProgressMonitor(new NullProgressMonitor()); job.run(null); if (releaseWaiting) { // atomically release waiting implicitJobs.removeWaiting(job); } } return blocking; }
/** * Performs the scheduling of a job. Does not perform any notifications. */ private void doSchedule(InternalJob job, long delay) { synchronized (lock) { //job may have been canceled already int state = job.internalGetState(); if (state != InternalJob.ABOUT_TO_SCHEDULE && state != Job.SLEEPING) return; //if it's a decoration job with no rule, don't run it right now if the system is busy if (job.getPriority() == Job.DECORATE && job.getRule() == null) { long minDelay = running.size() * 100; delay = Math.max(delay, minDelay); } if (delay > 0) { job.setStartTime(System.currentTimeMillis() + delay); changeState(job, Job.SLEEPING); } else { job.setStartTime(System.currentTimeMillis() + delayFor(job.getPriority())); job.setWaitQueueStamp(waitQueueCounter++); changeState(job, Job.WAITING); } } }
/** * Performs the scheduling of a job. Does not perform any notifications. */ private void doSchedule(InternalJob job, long delay) { synchronized (lock) { //job may have been canceled already int state = job.internalGetState(); if (state != InternalJob.ABOUT_TO_SCHEDULE && state != Job.SLEEPING) return; //if it's a decoration job with no rule, don't run it right now if the system is busy if (job.getPriority() == Job.DECORATE && job.getRule() == null) { long minDelay = running.size() * 100; delay = Math.max(delay, minDelay); } if (delay > 0) { job.setStartTime(System.currentTimeMillis() + delay); changeState(job, Job.SLEEPING); } else { job.setStartTime(System.currentTimeMillis() + delayFor(job.getPriority())); job.setWaitQueueStamp(waitQueueCounter.increment()); changeState(job, Job.WAITING); } } }
/** * Performs the scheduling of a job. Does not perform any notifications. */ private void doSchedule(InternalJob job, long delay) { synchronized (lock) { //job may have been canceled already int state = job.internalGetState(); if (state != InternalJob.ABOUT_TO_SCHEDULE && state != Job.SLEEPING) return; //if it's a decoration job with no rule, don't run it right now if the system is busy if (job.getPriority() == Job.DECORATE && job.getRule() == null) { long minDelay = running.size() * 100; delay = Math.max(delay, minDelay); } if (delay > 0) { job.setStartTime(System.currentTimeMillis() + delay); changeState(job, Job.SLEEPING); } else { job.setStartTime(System.currentTimeMillis() + delayFor(job.getPriority())); job.setWaitQueueStamp(waitQueueCounter.increment()); changeState(job, Job.WAITING); } } }
/** * Puts a job to sleep. Returns true if the job was successfully put to sleep. */ protected boolean sleep(InternalJob job) { synchronized (lock) { switch (job.getState()) { case Job.RUNNING : //cannot be paused if it is already running (as opposed to ABOUT_TO_RUN) if (job.internalGetState() == Job.RUNNING) return false; //job hasn't started running yet (aboutToRun listener) break; case Job.SLEEPING : //update the job wake time job.setStartTime(InternalJob.T_INFINITE); //change state again to re-shuffle the sleep queue changeState(job, Job.SLEEPING); return true; case Job.NONE : return true; case Job.WAITING : //put the job to sleep break; } job.setStartTime(InternalJob.T_INFINITE); changeState(job, Job.SLEEPING); } jobListeners.sleeping((Job) job); return true; }
/** * Puts a job to sleep. Returns true if the job was successfully put to sleep. */ protected boolean sleep(InternalJob job) { synchronized (lock) { switch (job.getState()) { case Job.RUNNING : //cannot be paused if it is already running (as opposed to ABOUT_TO_RUN) if (job.internalGetState() == Job.RUNNING) return false; //job hasn't started running yet (aboutToRun listener) break; case Job.SLEEPING : //update the job wake time job.setStartTime(InternalJob.T_INFINITE); //change state again to re-shuffle the sleep queue changeState(job, Job.SLEEPING); return true; case Job.NONE : return true; case Job.WAITING : //put the job to sleep break; } job.setStartTime(InternalJob.T_INFINITE); changeState(job, Job.SLEEPING); } jobListeners.sleeping((Job) job); return true; }
/** * Puts a job to sleep. Returns true if the job was successfully put to sleep. */ protected boolean sleep(InternalJob job) { synchronized (lock) { switch (job.getState()) { case Job.RUNNING : //cannot be paused if it is already running (as opposed to ABOUT_TO_RUN) if (job.internalGetState() == Job.RUNNING) return false; //job hasn't started running yet (aboutToRun listener) break; case Job.SLEEPING : //update the job wake time job.setStartTime(InternalJob.T_INFINITE); //change state again to re-shuffle the sleep queue changeState(job, Job.SLEEPING); return true; case Job.NONE : return true; case Job.WAITING : //put the job to sleep break; } job.setStartTime(InternalJob.T_INFINITE); changeState(job, Job.SLEEPING); } jobListeners.sleeping((Job) job); return true; }
/** * Performs the scheduling of a job. Does not perform any notifications. */ private void doSchedule(InternalJob job, long delay) { synchronized (lock) { //job may have been canceled already int state = job.internalGetState(); if (state != InternalJob.ABOUT_TO_SCHEDULE && state != Job.SLEEPING) return; //if it's a decoration job with no rule, don't run it right now if the system is busy if (job.getPriority() == Job.DECORATE && job.getRule() == null) { long minDelay = running.size() * 100; delay = Math.max(delay, minDelay); } if (delay > 0) { job.setStartTime(System.currentTimeMillis() + delay); changeState(job, Job.SLEEPING); } else { job.setStartTime(System.currentTimeMillis() + delayFor(job.getPriority())); job.setWaitQueueStamp(waitQueueCounter.increment()); changeState(job, Job.WAITING); } } }
/** * Puts a job to sleep. Returns true if the job was successfully put to sleep. */ protected boolean sleep(InternalJob job) { synchronized (lock) { switch (job.getState()) { case Job.RUNNING : //cannot be paused if it is already running (as opposed to ABOUT_TO_RUN) if (job.internalGetState() == Job.RUNNING) return false; //job hasn't started running yet (aboutToRun listener) break; case Job.SLEEPING : //update the job wake time job.setStartTime(InternalJob.T_INFINITE); //change state again to re-shuffle the sleep queue changeState(job, Job.SLEEPING); return true; case Job.NONE : return true; case Job.WAITING : //put the job to sleep break; } job.setStartTime(InternalJob.T_INFINITE); changeState(job, Job.SLEEPING); } jobListeners.sleeping((Job) job); return true; }
protected void schedule(InternalJob job, long delay, boolean reschedule) { if (!active) throw new IllegalStateException("Job manager has been shut down."); //$NON-NLS-1$ Assert.isNotNull(job, "Job is null"); //$NON-NLS-1$ Assert.isLegal(delay >= 0, "Scheduling delay is negative"); //$NON-NLS-1$ synchronized (lock) { //if the job is already running, set it to be rescheduled when done if (job.getState() == Job.RUNNING) { job.setStartTime(delay); return; } //can't schedule a job that is waiting or sleeping if (job.internalGetState() != Job.NONE) return; if (JobManager.DEBUG) JobManager.debug("Scheduling job: " + job); //$NON-NLS-1$ //remember that we are about to schedule the job //to prevent multiple schedule attempts from succeeding (bug 68452) changeState(job, InternalJob.ABOUT_TO_SCHEDULE); } //notify listeners outside sync block jobListeners.scheduled((Job) job, delay, reschedule); //schedule the job doSchedule(job, delay); //call the pool outside sync block to avoid deadlock pool.jobQueued(); }
protected void schedule(InternalJob job, long delay, boolean reschedule) { if (!active) throw new IllegalStateException("Job manager has been shut down."); //$NON-NLS-1$ Assert.isNotNull(job, "Job is null"); //$NON-NLS-1$ Assert.isLegal(delay >= 0, "Scheduling delay is negative"); //$NON-NLS-1$ synchronized (lock) { //if the job is already running, set it to be rescheduled when done if (job.getState() == Job.RUNNING) { job.setStartTime(delay); return; } //can't schedule a job that is waiting or sleeping if (job.internalGetState() != Job.NONE) return; if (JobManager.DEBUG) JobManager.debug("Scheduling job: " + job); //$NON-NLS-1$ //remember that we are about to schedule the job //to prevent multiple schedule attempts from succeeding (bug 68452) changeState(job, InternalJob.ABOUT_TO_SCHEDULE); } //notify listeners outside sync block jobListeners.scheduled((Job) job, delay, reschedule); //schedule the job doSchedule(job, delay); //call the pool outside sync block to avoid deadlock pool.jobQueued(); }
protected void schedule(InternalJob job, long delay, boolean reschedule) { if (!active) throw new IllegalStateException("Job manager has been shut down."); //$NON-NLS-1$ Assert.isNotNull(job, "Job is null"); //$NON-NLS-1$ Assert.isLegal(delay >= 0, "Scheduling delay is negative"); //$NON-NLS-1$ synchronized (lock) { //if the job is already running, set it to be rescheduled when done if (job.getState() == Job.RUNNING) { job.setStartTime(delay); return; } //can't schedule a job that is waiting or sleeping if (job.internalGetState() != Job.NONE) return; if (JobManager.DEBUG) JobManager.debug("Scheduling job: " + job); //$NON-NLS-1$ //remember that we are about to schedule the job //to prevent multiple schedule attempts from succeeding (bug 68452) changeState(job, InternalJob.ABOUT_TO_SCHEDULE); } //notify listeners outside sync block jobListeners.scheduled((Job) job, delay, reschedule); //schedule the job doSchedule(job, delay); //call the pool outside sync block to avoid deadlock pool.jobQueued(); }
protected void schedule(InternalJob job, long delay, boolean reschedule) { if (!active) throw new IllegalStateException("Job manager has been shut down."); //$NON-NLS-1$ Assert.isNotNull(job, "Job is null"); //$NON-NLS-1$ Assert.isLegal(delay >= 0, "Scheduling delay is negative"); //$NON-NLS-1$ synchronized (lock) { //if the job is already running, set it to be rescheduled when done if (job.getState() == Job.RUNNING) { job.setStartTime(delay); return; } //can't schedule a job that is waiting or sleeping if (job.internalGetState() != Job.NONE) return; if (JobManager.DEBUG) JobManager.debug("Scheduling job: " + job); //$NON-NLS-1$ //remember that we are about to schedule the job //to prevent multiple schedule attempts from succeeding (bug 68452) changeState(job, InternalJob.ABOUT_TO_SCHEDULE); } //notify listeners outside sync block jobListeners.scheduled((Job) job, delay, reschedule); //schedule the job doSchedule(job, delay); //call the pool outside sync block to avoid deadlock pool.jobQueued(); }
return false; default : changeState(job, Job.NONE);
return false; default : changeState(job, Job.NONE);
job.setThread(null); rescheduleDelay = job.getStartTime(); changeState(job, Job.NONE);
/** * Indicates that a job was running, and has now finished. Note that this method * can be called under OutOfMemoryError conditions and thus must be paranoid * about allocating objects. */ protected void endJob(InternalJob job, IStatus result, boolean notify) { long rescheduleDelay = InternalJob.T_NONE; synchronized (lock) { //if the job is finishing asynchronously, there is nothing more to do for now if (result == Job.ASYNC_FINISH) return; //if job is not known then it cannot be done if (job.getState() == Job.NONE) return; if (JobManager.DEBUG && notify) JobManager.debug("Ending job: " + job); //$NON-NLS-1$ job.setResult(result); job.setProgressMonitor(null); job.setThread(null); rescheduleDelay = job.getStartTime(); changeState(job, Job.NONE); } //notify listeners outside sync block final boolean reschedule = active && rescheduleDelay > InternalJob.T_NONE && job.shouldSchedule(); if (notify) jobListeners.done((Job) job, result, reschedule); //reschedule the job if requested and we are still active if (reschedule) schedule(job, rescheduleDelay, reschedule); }