private JobManager() { instance = this; initDebugOptions(); synchronized (lock) { waiting = new JobQueue(false); sleeping = new JobQueue(true); running = new HashSet(10); pool = new WorkerPool(this); } pool.setDaemon(JobOSGiUtils.getDefault().useDaemonThreads()); }
/** * Notification that a job has been added to the queue. Wake a worker, * creating a new worker if necessary. The provided job may be null. */ protected synchronized void jobQueued() { //if there is a sleeping thread, wake it up if (sleepingThreads > 0) { notify(); return; } //create a thread if all threads are busy if (busyThreads >= numThreads) { Worker worker = new Worker(this); worker.setDaemon(isDaemon); add(worker); if (JobManager.DEBUG) JobManager.debug("worker added to pool: " + worker); //$NON-NLS-1$ worker.start(); return; } }
@Override public final void resume() { synchronized (lock) { suspended = false; //poke the job pool pool.jobQueued(); } }
if (!manager.isActive()) { endWorker(worker); return null; incrementBusyThreads(); long hint = manager.sleepHint(); if (hint > 0) sleep(Math.min(hint, BEST_BEFORE)); job = manager.startJob(worker); if (job == null && (System.currentTimeMillis() - idleStart > BEST_BEFORE) && (numThreads - busyThreads) > MIN_THREADS) { endWorker(worker); return null; sleep(50); jobQueued(); decrementBusyThreads();
public void run() { setPriority(Thread.NORM_PRIORITY); try { while ((currentJob = pool.startJob(this)) != null) { currentJob.setThread(this); IStatus result = Status.OK_STATUS; pool.endJob(currentJob, result); if ((result.getSeverity() & (IStatus.ERROR | IStatus.WARNING)) != 0) RuntimeLog.log(result); } finally { currentJob = null; pool.endWorker(this);
/** * Signals the death of a worker thread. Note that this method can be called under * OutOfMemoryError conditions and thus must be paranoid about allocating objects. */ protected synchronized void endWorker(Worker worker) { if (remove(worker) && JobManager.DEBUG) JobManager.debug("worker removed from pool: " + worker); //$NON-NLS-1$ }
/** * Signals the end of a job. 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) { decrementBusyThreads(); //need to end rule in graph before ending job so that 2 threads //do not become the owners of the same rule in the graph if ((job.getRule() != null) && !(job instanceof ThreadJob)) { //remove any locks this thread may be owning on that rule manager.getLockManager().removeLockCompletely(Thread.currentThread(), job.getRule()); } manager.endJob(job, result, true); //ensure this thread no longer owns any scheduling rules manager.implicitJobs.endJob(job); }
if (!manager.isActive()) { endWorker(worker); return null; incrementBusyThreads(); long hint = manager.sleepHint(); if (hint > 0) sleep(Math.min(hint, BEST_BEFORE)); job = manager.startJob(worker); if (job == null && (System.currentTimeMillis() - idleStart > BEST_BEFORE) && (numThreads - busyThreads) > MIN_THREADS) { endWorker(worker); return null; sleep(50); jobQueued(); decrementBusyThreads();
/** * Signals the death of a worker thread. Note that this method can be called under * OutOfMemoryError conditions and thus must be paranoid about allocating objects. */ protected synchronized void endWorker(Worker worker) { if (remove(worker) && JobManager.DEBUG) JobManager.debug("worker removed from pool: " + worker); //$NON-NLS-1$ }
/** * Signals the end of a job. 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) { try { //need to end rule in graph before ending job so that 2 threads //do not become the owners of the same rule in the graph if ((job.getRule() != null) && !(job instanceof ThreadJob)) { //remove any locks this thread may be owning on that rule manager.getLockManager().removeLockCompletely(Thread.currentThread(), job.getRule()); } manager.endJob(job, result, true); //ensure this thread no longer owns any scheduling rules manager.implicitJobs.endJob(job); } finally { decrementBusyThreads(); } }
pool.shutdown(); jobListeners.remove(jobGroupUpdater);
if (!manager.isActive()) { endWorker(worker); return null; incrementBusyThreads(); long hint = manager.sleepHint(); if (hint > 0) sleep(Math.min(hint, BEST_BEFORE)); job = manager.startJob(); if (job == null && (System.currentTimeMillis() - idleStart > BEST_BEFORE) && (numThreads - busyThreads) > MIN_THREADS) { endWorker(worker); return null; sleep(50); jobQueued(); decrementBusyThreads();
private JobManager() { instance = this; initDebugOptions(); synchronized (lock) { waiting = new JobQueue(false); waitingThreadJobs = new JobQueue(false, false); sleeping = new JobQueue(true); running = new HashSet(10); yielding = new HashSet(10); pool = new WorkerPool(this); } pool.setDaemon(JobOSGiUtils.getDefault().useDaemonThreads()); internalWorker = new InternalWorker(this); internalWorker.setDaemon(JobOSGiUtils.getDefault().useDaemonThreads()); internalWorker.start(); }
public final void resume() { synchronized (lock) { suspended = false; //poke the job pool pool.jobQueued(); } }
/** * Signals the death of a worker thread. Note that this method can be called under * OutOfMemoryError conditions and thus must be paranoid about allocating objects. */ protected synchronized void endWorker(Worker worker) { if (remove(worker) && JobManager.DEBUG) JobManager.debug("worker removed from pool: " + worker); //$NON-NLS-1$ }
/** * Signals the end of a job. 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) { try { //need to end rule in graph before ending job so that 2 threads //do not become the owners of the same rule in the graph if ((job.getRule() != null) && !(job instanceof ThreadJob)) { //remove any locks this thread may be owning on that rule manager.getLockManager().removeLockCompletely(Thread.currentThread(), job.getRule()); } manager.endJob(job, result, true); //ensure this thread no longer owns any scheduling rules manager.implicitJobs.endJob(job); } finally { decrementBusyThreads(); } }
/** * Notification that a job has been added to the queue. Wake a worker, * creating a new worker if necessary. The provided job may be null. */ protected synchronized void jobQueued() { //if there is a sleeping thread, wake it up if (sleepingThreads > 0) { notify(); return; } //create a thread if all threads are busy if (busyThreads >= numThreads) { Worker worker = new Worker(this); worker.setDaemon(isDaemon); add(worker); if (JobManager.DEBUG) JobManager.debug("worker added to pool: " + worker); //$NON-NLS-1$ worker.start(); return; } }