private boolean isNewWorkersRequired(){
  statsUtil.pollStatsBrokerJobQueue();
  final StatsMessageListener statsMessageListener=statsUtil.getStatsMessageListener();
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("New worker Required - RequestQueue Stats: " + statsMessageListener.getStats());
  }
  boolean quickSpawnMode=false;
  int totalRemoteWorkerSpawned=getNumberOfWorkers();
  int consumerCount=statsMessageListener.getConsumers();
  int remoteWorkerCount=consumerCount - maxConcurrentInVmWorkerCount;
  int queueSize=statsMessageListener.getQueueSize();
  if (verboseLogLevel > 5) {
    Utilities.verboseLog("isNewWorkersRequired: maxConsumerSize : " + maxConsumerSize + " TotalConsumers: "+ consumerCount+ " QueueSize: "+ queueSize+ " totalRemoteWorkerSpawned: "+ totalRemoteWorkerSpawned+ " remoteWorkerCount: "+ remoteWorkerCount+ " queueConsumerRatio: "+ queueConsumerRatio+ " lifeRemaining: "+ lifeRemaining());
  }
  if (consumerCount < queueSize) {
    if (remoteWorkerCount > 0) {
      quickSpawnMode=(queueSize / remoteWorkerCount) > maxConcurrentInVmWorkerCount;
    }
 else {
      quickSpawnMode=queueSize > maxConcurrentInVmWorkerCount;
    }
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("New worker Required  quickSpawnMode: " + quickSpawnMode);
    }
    if (verboseLogLevel > 5) {
      Utilities.verboseLog("isNewWorkersRequired: maxConsumerSize : " + maxConsumerSize + " currentRemoteWorkersCount "+ remoteWorkerCount+ " queueConsumerRatio: "+ queueConsumerRatio+ " quickSpawnMode: "+ quickSpawnMode+ " completionTargetMillis: "+ lifeRemaining() / completionFactor);
    }
    return (statsMessageListener.newWorkersRequired((int)(lifeRemaining() / completionFactor)) && (consumerCount < maxConsumerSize) && (consumerCount < queueSize / queueConsumerRatio)) || (quickSpawnMode);
  }
  return false;
}

private boolean isNewWorkersRequired ( ) { statsUtil . pollStatsBrokerJobQueue ( ) ; final StatsMessageListener statsMessageListener = statsUtil . getStatsMessageListener ( ) ; if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "New worker Required - RequestQueue Stats: " + statsMessageListener . getStats ( ) ) ; } boolean quickSpawnMode = false ; int totalRemoteWorkerSpawned = getNumberOfWorkers ( ) ; int consumerCount = statsMessageListener . getConsumers ( ) ; int remoteWorkerCount = consumerCount - maxConcurrentInVmWorkerCount ; int queueSize = statsMessageListener . getQueueSize ( ) ; if ( verboseLogLevel > 5 ) { Utilities . verboseLog ( "isNewWorkersRequired: maxConsumerSize : " + maxConsumerSize + " TotalConsumers: " + consumerCount + " QueueSize: " + queueSize + " totalRemoteWorkerSpawned: " + totalRemoteWorkerSpawned + " remoteWorkerCount: " + remoteWorkerCount + " queueConsumerRatio: " + queueConsumerRatio + " lifeRemaining: " + lifeRemaining ( ) ) ; } if ( consumerCount < queueSize ) { if ( remoteWorkerCount > 0 ) { quickSpawnMode = ( queueSize / remoteWorkerCount ) > maxConcurrentInVmWorkerCount ; } else { quickSpawnMode = queueSize > maxConcurrentInVmWorkerCount ; } if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "New worker Required  quickSpawnMode: " + quickSpawnMode ) ; } if ( verboseLogLevel > 5 ) { Utilities . verboseLog ( "isNewWorkersRequired: maxConsumerSize : " + maxConsumerSize + " currentRemoteWorkersCount " + remoteWorkerCount + " queueConsumerRatio: " + queueConsumerRatio + " quickSpawnMode: " + quickSpawnMode + " completionTargetMillis: " + lifeRemaining ( ) / completionFactor ) ; } return ( statsMessageListener . newWorkersRequired ( ( int ) ( lifeRemaining ( ) / completionFactor ) ) && ( consumerCount < maxConsumerSize ) && ( consumerCount < queueSize / queueConsumerRatio ) ) || ( quickSpawnMode ) ; } return false ; }
statsmessagelistener . newworkersrequired = expectedcompletiontime ( ) > liferemaining / completiontargetfactor check if number of remoteconsumers < maxconsumersize check if number of consumers < getqueuesize ( ) / queueconsumerratio
