Scala futures creating endless streams in actors

I use futures and timeouts inside the actor so that the system does not wait for the 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 contributors. I notice that the number of working threads increases endlessly. "MyCommand.sh" usually takes a few seconds. Why is this happening? Is there a limit to using futures?

change 1:

After some time, all processes that took 1 or 2 seconds start the TIMEOUT log.

0
source share

All Articles