------------------------------------------------------ worker methods
2625
public void launchAddWorkerDialog() {
        if (addWorkerDialog == null) {
            addWorkerDialog = new AddResourceDialog(
                    securityFramework.getSecurityContext(getProxy().getNameToken()),
                    resourceDescriptionRegistry.lookup(workerAddressTemplate),
                    new AddResourceDialog.Callback() {
                        @Override
                        public void onAdd(ModelNode payload) {
                            window.hide();
                            circuit.dispatch(new AddWorker(payload));
                        }

                        @Override
                        public void onCancel() {
                           window.hide();
                        }

                    }
            );
        } else {
            addWorkerDialog.clearValues();
        }

        window = new DefaultWindow("Worker");
        window.setWidth(480);
        window.setHeight(360);
        window.setWidget(addWorkerDialog);
        window.setGlassEnabled(true);
        window.center();
    }
519106
private void startWorkers(final ExecutorService executorService, final int numTasks) {
        for (int i = 0; i < numTasks; i++) {
            workerFutures.add(executorService.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    runWorkLoop();
                    return null;
                }
            }));
        }
    }
1057610
function WorkerHandler(script, _options) {
  this.script = script || getDefaultWorker();
  var options = _options || {};
  this.debugPort = options.debugPort;

  if (environment.platform == 'browser') {
    // check whether Worker is supported by the browser
    // Workaround for a bug in PhantomJS (Or QtWebkit): https://github.com/ariya/phantomjs/issues/14534
    if (typeof Worker !== 'function' && (typeof Worker !== 'object' || typeof Worker.prototype.constructor !== 'function')) {
      throw new Error('WorkerPool: Web workers not supported by the browser');
    }

    this.worker = setupBrowserWorker(this.script, Worker);
  } else {
    var WorkerThreads;

    if (options.nodeWorker === 'thread') {
      WorkerThreads = ensureWorkerThreads();
      this.worker = setupWorkerThreadWorker(this.script, WorkerThreads);
    } else if (options.nodeWorker === 'auto') {
      WorkerThreads = tryRequire('worker_threads');
      if (WorkerThreads) {
        this.worker = setupWorkerThreadWorker(this.script, WorkerThreads);
      } else {
        this.worker = setupProcessWorker(this.script, resolveForkOptions(options), require('child_process'));
      }
    } else {
      this.worker = setupProcessWorker(this.script, resolveForkOptions(options), require('child_process'));
    }
  }

  var me = this;

  // The ready message is only sent if the worker.add method is called (And the default script is not used)
  if (!script) {
    this.worker.ready = true;
  }

  // queue for requests that are received before the worker is ready
  this.requestQueue = [];
  this.worker.on('message', function (response) {
    if (typeof response === 'string' && response === 'ready') {
      me.worker.ready = true;
      dispatchQueuedRequests();
    } else {
      // find the task from the processing queue, and run the tasks callback
      var id = response.id;
      var task = me.processing[id];
      if (task !== undefined) {
        // remove the task from the queue
        delete me.processing[id];

        // test if we need to terminate
        if (me.terminating === true) {
          // complete worker termination if all tasks are finished
          me.terminate();
        }

        // resolve the task's promise
        if (response.error) {
          task.resolver.reject(objectToError(response.error));
        }
        else {
          task.resolver.resolve(response.result);
        }
      }
    }
  });

  // reject all running tasks on worker error
  function onError(error) {
    me.terminated = true;
    if (me.terminating && me.terminationHandler) {
      me.terminationHandler(me);
    }
    me.terminating = false;

    for (var id in me.processing) {
      if (me.processing[id] !== undefined) {
        me.processing[id].resolver.reject(error);
      }
    }
    me.processing = Object.create(null);
  }

  // send all queued requests to worker
  function dispatchQueuedRequests()
  {
    me.requestQueue.forEach(me.worker.send.bind(me.worker));
    me.requestQueue = [];
  }

  var worker = this.worker;
  // listen for worker messages error and exit
  this.worker.on('error', onError);
  this.worker.on('exit', function (exitCode, signalCode) {
    var message = 'Workerpool Worker terminated Unexpectedly\n';

    message += '    exitCode: `' + exitCode + '`\n';
    message += '    signalCode: `' + signalCode + '`\n';

    message += '    workerpool.script: `' +  me.script + '`\n';
    message += '    spawnArgs: `' +  worker.spawnargs + '`\n';
    message += '    spawnfile: `' + worker.spawnfile + '`\n'

    message += '    stdout: `' + worker.stdout + '`\n'
    message += '    stderr: `' + worker.stderr + '`\n'

    onError(new Error(message));
  });

  this.processing = Object.create(null); // queue with tasks currently in progress

  this.terminating = false;
  this.terminated = false;
  this.terminationHandler = null;
  this.lastId = 0;
}
391731
def worker(self):
        
        if self._worker is None:
            self._worker = XOrbLookupWorker(self.isThreadEnabled())
            self._worker.setBatchSize(self._batchSize)
            self._worker.setBatched(not self.isThreadEnabled())
            
            # connect the worker
            self.loadRequested.connect(self._worker.loadRecords)
            self._worker.loadingStarted.connect(self.markLoadingStarted)
            self._worker.loadingFinished.connect(self.markLoadingFinished)
            self._worker.loadedRecords.connect(self.addRecordsFromThread)
        
        return self._worker
45253
public void manage(Collection<SupervisedWorker> workers)
   {
      if(workers == null)
         return;
      
      this.workers.clear();
      
      SupervisedWorker worker = null;
      for (Iterator<SupervisedWorker> i = workers.iterator(); i.hasNext();)
      {
         worker = i.next();
         
         this.manage(worker);
      }
      
   }
969081
function dispatchWorkItems() {
	var i,
		workItem;
	if (!buffer.isEmpty()) {
		i = workerJobCount.indexOf(0);
		if(i >= 0) { //Free worker found
			workItem = buffer.next();

			// Send task to worker
			workerExec(i, workItem);

			//Check for more free workers
			dispatchWorkItems();
		}
	}
}
940441
def createWorkers(self, num_workers):
        
        for i in range(num_workers):
            self.workers.append(WorkerThread(self._requests_queue))
727957
function handleArrayResult(m, workerIdx) {
	var job = jobs[m.context.jobID],
		partition = m.context.partition,
		subResult = m.result,
		result = [],
		i;
	
	job.result[partition] = subResult;

	// Increase callback count.
	job.cbCount++;
	
	// When all workers are finished return result
	if(job.cbCount === workers.length) {
		for (i = 0; i < job.result.length; i++) {
			result = result.concat(job.result[i]);
		};
		
		// Cle
		job.cb(null, result);
	}

	// Worker is finished.
	workerJobCount[workerIdx]--;
	dispatchWorkItems();
}
988615
function handleWorkerRestart(worker, code, signal) {
		delete self.workers[worker.id];
		if (self.reviveWorkers) {
			var zombie = cluster.fork({
				config: JSON.stringify(self.config)
			});
			self.workers[zombie.id] = zombie;
		}
	}
331810
private void addThread() {
        Thread t = new WorkerThread(workQueue);
        threads.add(t);
        t.start();            
    }
209074
def _create_worker(self, method, *args, **kwargs):
        """"""
        # FIXME: this might be heavy...
        thread = QThread()
        worker = ClientWorker(method, args, kwargs)
        worker.moveToThread(thread)
        worker.sig_finished.connect(self._start)
        worker.sig_finished.connect(thread.quit)
        thread.started.connect(worker.start)
        self._queue.append(thread)
        self._threads.append(thread)
        self._workers.append(worker)
        self._start()
        return worker
16972
function WorkerPool(pool_size, file_name) {
  events.EventEmitter.call(this);

  this._pool_size = pool_size;
  this._file_name = file_name;

  this._workers = []; // All the available workers
  this._active_workers = []; // Active workers
  this._idle_workers = []; // Idle workers
  this._pending_removal_workers = []; // Workers which are pending to be removed

  this._pending_jobs = [];
  this._is_terminated = false;
  this._pending_jobs_timeout_id = null;

  this._initialize();
}
1174344
def join(self):
        """"""
        for thread in self.worker_threads:
            thread.join()
        WorkerThread.join(self)
753041
def initialize_worker(self):
        """"""
        worker_thread = threading.Thread(
            name="WorkerThread", target=message_worker, args=(self,))
        worker_thread.setDaemon(True)
        worker_thread.start()
1014911
public void start() {
        switch (WORKER_STATE_UPDATER.get(this)) {
            case WORKER_STATE_INIT:
                if (WORKER_STATE_UPDATER.compareAndSet(this, WORKER_STATE_INIT, WORKER_STATE_STARTED)) {
                    workerThread.start();
                }
                break;
            case WORKER_STATE_STARTED:
                break;
            case WORKER_STATE_SHUTDOWN:
                throw new IllegalStateException("cannot be started once stopped");
            default:
                throw new Error("Invalid WorkerState");
        }

        // Wait until the startTime is initialized by the worker.
        while (startTime == 0) {
            try {
                startTimeInitialized.await();
            } catch (InterruptedException ignore) {
                // Ignore - it will be ready very soon.
            }
        }
    }
1021504
private void queueWork(Work work) {
        try {
            logger.debug("Queueing work {}", work);
            executor.submit(new EventWorker(work, this));
        } catch (RejectedExecutionException e) {
            logger.error("Unable to queue a received event! ", e);
        }
        checkQueueSize();
    }
945487
public function main()
    {
        $logger = Log::engine($this->params['logger']);
        $engine = $this->getEngine($logger);
        $worker = $this->getWorker($engine, $logger);
        $worker->work();
    }