我在actor中使用future和timeout来避免系统等待多长时间执行命令:

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());

我从不同的演员那里运行了这个代码数百次 . 我注意到正在运行的线程数无限增加 . “myCommand.sh”通常需要几秒钟才能运行 . 为什么会这样?使用期货有限制吗?

edit 1:

运行一段时间后,运行1或2秒的所有进程开始记录TIMEOUT .