문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top