Pergunta

How can I add delay when empty queue is filling with next thread? Ex:

int numberOfThreads = 55;

private static ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);

int counter=0;
for(TblHomePageUrl tblHomePageUrl : mainTable)
{
    legalInstituteIDList.add(tblHomePageUrl.getIntLegalInstitutionID());

    WPCrawlerThread wpThread = new WPCrawlerThread(tblHomePageUrl, maxDepth, politenessDelay);
    executor.execute(wpThread);
    threadList.add(wpThread);

    if(counter<=numThreads){
        try {
            Thread.sleep(10000);
        } catch(InterruptedException ex) {}
    }
    counter++;                      
}

I'm sending post request to google when start each Thread. If 2 or 3 thread run same time I am blocking from Google. If i can add a small delay between filling threads. I'll stay away from blocking. I'm using java. I need to setting to executor.

Foi útil?

Solução

Maybe you can try to use ScheduledExecutorService instead of ExecutorService. The documentation about ScheduledExecutorService says:

An ExecutorService that can schedule commands to run after a given delay, or to execute periodically.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top