Scala futures creating infinity threads in actors

℡╲_俬逩灬. 提交于 2019-12-25 07:58:32

问题


I am using futures and timeouts inside an actor to avoid system to wait to long for a command to execute:

  val _output = future { "myCommand.sh" !! }

  output = try {
    Await.result(_output, 3 minutes)
  } catch {
    case e: TimeoutException => {
      LOG.warn(s"Timeout for command. Will return empty.")
      ""
    }
  }

  System.out.println("Number of active threads from the given thread: " + Thread.activeCount());

I run this code hundreds of times from different actors. I am noticing that the number of running threads is increasing infinitely. The "myCommand.sh" usually take a few seconds to run. Why this happens? Is there any limit for using futures?

edit 1:

After some time running, all processes that took 1 or 2 seconds to run start logging TIMEOUT.

来源:https://stackoverflow.com/questions/22187186/scala-futures-creating-infinity-threads-in-actors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!