Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to limit concurrency when using actors in Scala?
    primarykey
    data
    text
    <p>I'm coming from Java, where I'd submit <code>Runnable</code>s to an <code>ExecutorService</code> backed by a thread pool. It's very clear in Java how to set limits to the size of the thread pool.</p> <p>I'm interested in using Scala actors, but I'm unclear on how to limit concurrency.</p> <p>Let's just say, hypothetically, that I'm creating a web service which accepts "jobs". A job is submitted with <code>POST</code> requests, and I want my service to enqueue the job then immediately return <code>202 Accepted</code> — i.e. the jobs are handled asynchronously.</p> <p>If I'm using actors to process the jobs in the queue, how can I limit the number of simultaneous jobs that are processed?</p> <p>I can think of a few different ways to approach this; I'm wondering if there's a community best practice, or at least, some clearly established approaches that are somewhat standard in the Scala world.</p> <p>One approach I've thought of is having a single coordinator actor which would manage the job queue and the job-processing actors; I suppose it could use a simple int field to track how many jobs are currently being processed. I'm sure there'd be some gotchyas with that approach, however, such as making sure to track when an error occurs so as to decrement the number. That's why I'm wondering if Scala already provides a simpler or more encapsulated approach to this.</p> <p>BTW I tried to ask this question <a href="https://stackoverflow.com/questions/1986122/does-it-make-sense-to-use-a-pool-of-actors">a while ago</a> but I asked it badly.</p> <p>Thanks!</p>
    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