2

I m using dispatch library in my sbt project. When I initialize three future and run them it is working perfectly But I increase one more future then it goes to a loop.

My code:

    //Initializing Futures
    def sequenceOfFutures() ={

     var pageNumber: Int = 1
        var list ={Seq(Future{})}

        for (pageNumber <- 1 to 4) {
          list ++= {
            Seq(
              Future { 
              str= getRequestFunction(pageNumber); 
              GlobalObjects.sleep(Random.nextInt(1500)); 

              }
              )
          }
        }
    Future.sequence(list)
    }
Await.result(sequenceOfFutures, Duration.Inf)

And then getRequestionFunction(pageNumber) code:

def getRequestionFunction(pageNumber)={

  val h=Http("scala.org", as_str)

while(h.isComplete){

   Thread,sleep(1500);
}

}

I tried based on one suggestion from How to configure a fine tuned thread pool for futures?

I added this to my code:

import java.util.concurrent.Executors
import scala.concurrent._

implicit val ec = new ExecutionContext {
    val threadPool = Executors.newFixedThreadPool(1000);

    def execute(runnable: Runnable) {
        threadPool.submit(runnable)
    }

    def reportFailure(t: Throwable) {}
}// Still didn't work 

So when I use more than four Futures then it keeps await forever. Is there some solution to fix it?

But it didn't work Could someone please suggest how to solve this issue?

Community
  • 1
  • 1
DSKVP
  • 663
  • 2
  • 11
  • 19

0 Answers0