Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing concurrently in Scala
    primarykey
    data
    text
    <p>As <a href="https://stackoverflow.com/questions/1007010/can-scala-actors-process-multiple-messages-simultaneously/1007310#1007310">in my own answer to my own question</a>, I have the situation whereby I am processing a large number of events which arrive on a queue. Each event is handled in exactly the same manner and each even can be handled independently of all other events. </p> <p>My program takes advantage of the Scala concurrency framework and many of the processes involved are modelled as <code>Actor</code>s. As <code>Actor</code>s process their messages sequentially, they are not well-suited to this particular problem (even though my <em>other</em> actors are performing actions which <em>are</em> sequential). As I want Scala to "control" all thread creation (which I assume is the point of it having a concurrency system in the first place) it seems I have 2 choices:</p> <ol> <li>Send the events to a pool of event processors, which I control</li> <li>get my <code>Actor</code> to process them concurrently by some other mechanism</li> </ol> <p>I would have thought that #1 negates the point of using the actors subsystem: <em>how many processor actors should I create?</em> being one obvious question. These things are supposedly hidden from me and solved by the subsystem.</p> <p>My answer was to do the following:</p> <pre><code>val eventProcessor = actor { loop { react { case MyEvent(x) =&gt; //I want to be able to handle multiple events at the same time //create a new actor to handle it actor { //processing code here process(x) } } } } </code></pre> <p>Is there a better approach? Is this incorrect?</p> <p><em>edit: A possibly better approach is:</em></p> <pre><code>val eventProcessor = actor { loop { react { case MyEvent(x) =&gt; //Pass processing to the underlying ForkJoin framework Scheduler.execute(process(e)) } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload