/** * Sets the sync request client count. This is how many concurrent threads are processing sync * request. This value is bounded: MIN_SYNC_REQUEST_CLIENTS <= count <= MAX_SYNC_REQUEST_CLIENTS. * * @param count number of sync request clients */ public void setSyncRequestClientCount(int count) { m_syncRequestClientCount = boundSyncRequestClientCount(count); if (m_syncRequestClientCount != count) { s_log.info( "Sync request client count [" + count + " ms] adjusted to fit bounds [" + m_syncRequestClientCount + " ms]."); } ThreadUtils.alert(this); }
/** * Main loop of the broker thread. Invoked when the thread is started and terminates when the * terminate flag is set. Some definitions: 1) Terminated Thread - A SyncRequestClient thread that * has been requested to terminate but may still be finishing up a request. 2) Stopped Thread - A * SyncRequestClient thread that has terminated and has stopped running. */ protected void service() { while (getState() == State.Running) { // Move the newly terminated threads to the terminated list to let them spin down. removeTerminatedClients(); // Remove the threads on the terminated list that are no longer spinning. purgeStoppedClients(); // Adjust the number of running threads adjustClientCount(); // Brief pause... ThreadUtils.alertableSleep(this, s_cycleTimeMS); } // Terminate all running threads reduceClients(0); // Wait for terminated threads to stop running. while (m_terminatedClients.size() > 0) { purgeStoppedClients(); ThreadUtils.alertableSleep(this, s_cycleTimeMS); } }