@Override public boolean apply(final Job input) { return rule.equals(input.getRule()); }
/** * For debugging purposes only */ private static String printJobName(Job job) { if (job instanceof ThreadJob) { Job realJob = ((ThreadJob) job).realJob; if (realJob != null) return realJob.getClass().getName(); return "ThreadJob on rule: " + job.getRule(); //$NON-NLS-1$ } return job.getClass().getName(); }
/** * For debugging purposes only */ private static String printJobName(Job job) { if (job instanceof ThreadJob) { Job realJob = ((ThreadJob) job).realJob; if (realJob != null) return realJob.getClass().getName(); return "ThreadJob on rule: " + job.getRule(); //$NON-NLS-1$ } return job.getClass().getName(); }
/** * For debugging purposes only */ private static String printJobName(Job job) { if (job instanceof ThreadJob) { Job realJob = ((ThreadJob) job).realJob; if (realJob != null) return realJob.getClass().getName(); return "ThreadJob on rule: " + job.getRule(); //$NON-NLS-1$ } return job.getClass().getName(); }
/** * For debugging purposes only */ private static String printJobName(Job job) { if (job instanceof ThreadJob) { Job realJob = ((ThreadJob) job).realJob; if (realJob != null) return realJob.getClass().getName(); return "ThreadJob on rule: " + job.getRule(); //$NON-NLS-1$ } return job.getClass().getName(); }
@Override public ISchedulingRule currentRule() { //check thread job first, because actual current job may have null rule Job currentJob = implicitJobs.getThreadJob(Thread.currentThread()); if (currentJob != null) return currentJob.getRule(); currentJob = currentJob(); if (currentJob != null) return currentJob.getRule(); return null; }
@Override public ISchedulingRule currentRule() { //check thread job first, because actual current job may have null rule Job currentJob = implicitJobs.getThreadJob(Thread.currentThread()); if (currentJob != null) return currentJob.getRule(); currentJob = currentJob(); if (currentJob != null) return currentJob.getRule(); return null; }
public ISchedulingRule currentRule() { //check thread job first, because actual current job may have null rule Job currentJob = implicitJobs.getThreadJob(Thread.currentThread()); if (currentJob != null) return currentJob.getRule(); currentJob = currentJob(); if (currentJob != null) return currentJob.getRule(); return null; }
/** * Adds a new scheduling rule to the stack of rules for this thread. Throws * a runtime exception if the new rule is not compatible with the base * scheduling rule for this thread. */ void push(final ISchedulingRule rule) { final ISchedulingRule baseRule = getRule(); if (++top >= ruleStack.length) { ISchedulingRule[] newStack = new ISchedulingRule[ruleStack.length * 2]; System.arraycopy(ruleStack, 0, newStack, 0, ruleStack.length); ruleStack = newStack; } ruleStack[top] = rule; if (JobManager.DEBUG_BEGIN_END) lastPush = (RuntimeException) new RuntimeException().fillInStackTrace(); //check for containment last because we don't want to fail again on endRule if (baseRule != null && rule != null && !baseRule.contains(rule)) illegalPush(rule, baseRule); }
public void threadChange(Thread thread) { // we must make sure we aren't transferring control away from a thread that // already owns a scheduling rule because this is deadlock prone (bug 105491) if (rule == null) { return; } Job currentJob = Job.getJobManager().currentJob(); if (currentJob == null) { return; } ISchedulingRule currentRule = currentJob.getRule(); if (currentRule == null) { return; } throw new IllegalStateException( "Cannot fork a thread from a thread owning a rule"); // $NON-NLS-1$ }
@Override public void threadChange(Thread thread) { //we must make sure we aren't transferring control away from a thread that //already owns a scheduling rule because this is deadlock prone (bug 105491) if (rule == null) { return; } Job currentJob = Job.getJobManager().currentJob(); if (currentJob == null) { return; } ISchedulingRule currentRule = currentJob.getRule(); if (currentRule == null) { return; } throw new IllegalStateException("Cannot fork a thread from a thread owning a rule"); //$NON-NLS-1$ }
/** * Indicates the start of a wait on a scheduling rule. Report the * blockage to the progress manager and update the lock manager. * @param monitor The monitor to report blocking to * @param blockingJob The job that is blocking this thread, or <code>null</code> */ private void waitStart(IProgressMonitor monitor, InternalJob blockingJob) { manager.getLockManager().addLockWaitThread(Thread.currentThread(), getRule()); isBlocked = true; manager.reportBlocked(monitor, blockingJob); } }
/** * Reports that this thread was blocked, but is no longer blocked and is able * to proceed. * @param monitor The monitor to report unblocking to. */ private void waitEnd(IProgressMonitor monitor) { final LockManager lockManager = manager.getLockManager(); final Thread currentThread = Thread.currentThread(); if (isRunning()) { lockManager.addLockThread(currentThread, getRule()); //need to re-acquire any locks that were suspended while this thread was blocked on the rule lockManager.resumeSuspendedLocks(currentThread); } else { //tell lock manager that this thread gave up waiting lockManager.removeLockWaitThread(currentThread, getRule()); } }
/** * Implements IJobManager#transferRule(ISchedulingRule, Thread) */ synchronized void transfer(ISchedulingRule rule, Thread destinationThread) { //nothing to do for null if (rule == null) return; final Thread currentThread = Thread.currentThread(); //nothing to do if transferring to the same thread if (currentThread == destinationThread) return; //ensure destination thread doesn't already have a rule ThreadJob job = (ThreadJob) threadJobs.get(destinationThread); Assert.isLegal(job == null, "Transfer rule to job that already owns a rule"); //$NON-NLS-1$ //ensure calling thread owns the job being transferred job = (ThreadJob) threadJobs.get(currentThread); Assert.isNotNull(job, "transferRule without beginRule"); //$NON-NLS-1$ Assert.isLegal(job.getRule() == rule, "transferred rule " + rule + " does not match beginRule: " + job.getRule()); //$NON-NLS-1$ //$NON-NLS-2$ //transfer the thread job without ending it job.setThread(destinationThread); threadJobs.remove(currentThread); threadJobs.put(destinationThread, job); //transfer lock if (job.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); manager.getLockManager().addLockThread(destinationThread, rule); } } }
private void endThreadJob(ThreadJob threadJob, boolean resume) { Thread currentThread = Thread.currentThread(); //clean up when last rule scope exits threadJobs.remove(currentThread); ISchedulingRule rule = threadJob.getRule(); if (resume && rule != null) suspendedRules.remove(rule); //if this job had a rule, then we are essentially releasing a lock //note it is safe to do this even if the acquire was aborted if (threadJob.acquireRule) { manager.getLockManager().removeLockThread(currentThread, rule); notifyWaitingThreadJobs(); } //if the job was started, we need to notify job manager to end it if (threadJob.isRunning()) manager.endJob(threadJob, Status.OK_STATUS, false); recycle(threadJob); }
Job job= Job.getJobManager().currentJob(); if (job != null) rule= job.getRule(); IRunnableWithProgress runnable= null; if (rule != null)
Job job= Job.getJobManager().currentJob(); if (job != null) rule= job.getRule(); IRunnableWithProgress runnable= null; if (rule != null)
public IStatus validateInJob(final IValidationContext helper, final IReporter reporter) throws ValidationException { Job currentJob = Platform.getJobManager().currentJob(); ISchedulingRule rule = null; if (currentJob != null) { rule = currentJob.getRule(); } IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { try { doValidate(helper, reporter); } catch (ValidationException e) { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID_JSP_CORE, 0, PLUGIN_ID_JSP_CORE, e)); } } }; try { JavaCore.run(validationRunnable, rule, new NullProgressMonitor()); } catch (CoreException e) { if (e.getCause() instanceof ValidationException) { throw (ValidationException) e.getCause(); } throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e); } return Status.OK_STATUS; } }
Job job= Job.getJobManager().currentJob(); if (job != null) rule= job.getRule(); IRunnableWithProgress runnable= null; if (rule != null)
public boolean performFinish() { IWorkspaceRunnable op= new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { finishPage(monitor); } catch (InterruptedException e) { throw new OperationCanceledException(e.getMessage()); } } }; try { ISchedulingRule rule= null; Job job= Job.getJobManager().currentJob(); if (job != null) rule= job.getRule(); IRunnableWithProgress runnable= null; if (rule != null) runnable= new WorkbenchRunnableAdapter(op, rule, true); else runnable= new WorkbenchRunnableAdapter(op, getSchedulingRule()); getContainer().run(canRunForked(), true, runnable); } catch (InvocationTargetException e) { handleFinishException(getShell(), e); return false; } catch (InterruptedException e) { return false; } return true; }