From b9716a7da6c3f3587ddd9918fd5048903ec78296 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 4 Nov 2019 07:06:01 +0800 Subject: actor readme --- docs/pages/4 - Cask Actors.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/pages/4 - Cask Actors.md b/docs/pages/4 - Cask Actors.md index d5799f0..5c7cd27 100644 --- a/docs/pages/4 - Cask Actors.md +++ b/docs/pages/4 - Cask Actors.md @@ -422,6 +422,11 @@ override def run(msg: Msg): Unit = { } ``` +Note that if you have multiple actors sending messages to each other, by default +they run on a thread pool and so the `println` messages above may become +interleaved and hard to read. To resolve that, you can try +[Running Actors Single Threaded](#running-actors-single-threaded). + ### Debugging using Context Logging Apart from logging individual Actors, you can also insert logging into the @@ -461,6 +466,8 @@ cask.actor.JvmActorsTest$Writer$2@3bb87fa0 <- SSBhbSBjb3csIEkgYW0gY293 cask.actor.JvmActorsTest$Writer$2@3bb87fa0 <- SGVhciBtZSBtb28sIG1vb29v ``` +### Running Actors Single Threaded + We can also replace the default `scala.concurrent.ExecutionContext.global` executor with a single-threaded executor, if we want our Actor pipeline to behave 100% deterministically: @@ -482,4 +489,4 @@ Any asynchronous Actor pipeline should be able to run no a `newSingleThreadExecutor`. While it would be slower than running on the default thread pool, it should make execution of your actors much more deterministic - only one actor will be running at a time - and make it easier to track down -logical bugs without multithreaded parallelism getting in the way. \ No newline at end of file +logical bugs without multithreaded parallelism getting in the way. -- cgit v1.2.3