/** * For debugging purposes only */ public static String printState(Job job) { return printState(((InternalJob) job).internalGetState()); }
/** * For debugging purposes only */ public static String printState(Job job) { return printState(((InternalJob) job).internalGetState()); }
/** * For debugging purposes only */ public static String printState(Job job) { return printState(((InternalJob) job).internalGetState()); }
private void waitForUnblocked(InternalJob theJob) { // wait until theJob leaves WAITING state boolean interrupted = false; synchronized (theJob.jobStateLock) { if (theJob instanceof ThreadJob) { // We can't acquire the implicitJob lock while holding jobStateLock, // so use isWaiting instead. while (((ThreadJob) theJob).isWaiting) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } else { while (theJob.internalGetState() == Job.WAITING) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } } if (interrupted) Thread.currentThread().interrupt(); }
private void waitForUnblocked(InternalJob theJob) { // wait until theJob leaves WAITING state boolean interrupted = false; synchronized (theJob.jobStateLock) { if (theJob instanceof ThreadJob) { // We can't acquire the implicitJob lock while holding jobStateLock, // so use isWaiting instead. while (((ThreadJob) theJob).isWaiting) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } else { while (theJob.internalGetState() == Job.WAITING) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } } if (interrupted) Thread.currentThread().interrupt(); }
private void waitForUnblocked(InternalJob theJob) { // wait until theJob leaves WAITING state boolean interrupted = false; synchronized (theJob.jobStateLock) { if (theJob instanceof ThreadJob) { // We can't acquire the implicitJob lock while holding jobStateLock, // so use isWaiting instead. while (((ThreadJob) theJob).isWaiting) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } else { while (theJob.internalGetState() == Job.WAITING) { try { theJob.jobStateLock.wait(); } catch (InterruptedException e) { interrupted = true; } } } } if (interrupted) Thread.currentThread().interrupt(); }
/** * 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); } } }
/** * 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); } } }
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(); }
/** * 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; }
/** * 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; }
case Job.RUNNING : if (job.internalGetState() == Job.RUNNING) { monitor = job.getProgressMonitor(); runCanceling = !job.isRunCanceled();
case Job.RUNNING : if (job.internalGetState() == Job.RUNNING) { monitor = job.getProgressMonitor(); runCanceling = !job.isRunCanceled();