开发者

[Scala]: Problem with Actors and blocking IO [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 3 years ago.

Improve this question

I'm having a little problem with Scala Actors and blocking IO. I'm using an actor that itself has an anonymous actor that consumes an input stream. The problem is that this stream only reads one line and then blocks without waking up again.开发者_JAVA百科 What confuses me is that it worked when the consumption took place in the act method (coincidence?). The application itself has some more actors and java threads doing some work.

My question is: What is the common practice to avoid such problems? Any pointers?

The code that causes this problem looks somewhat like this:

object TestActor extends Actor {

  private val instream = actor {
    loop {
      try {
        println(processInput(input.readLine)) //bufferedinputstream. blocks, no wakeup
      } catch {
        case e: Exception =>
          println(e.toString)
      }
    }
  }


  def act(): Unit = {
    react {
      ...
      case _ => {}
    }
  }
}

Regards, raichoo


The call to readLine is inside loop{} so it's going to happen over and over until it blocks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜