Как определять пул потоков для агентов

std::vector v; поднимает sizeof(v) пространство. Это могло бы варьироваться реализацией, таким образом выполнить его и узнать, сколько требуется для Вас.

12
задан agilefall 20 October 2009 в 23:31
поделиться

2 ответа

Я считаю, что вы можете сделать что-то вроде этого:

trait MyActor extends Actor {
  val pool = ... // git yer thread pool here
  override def scheduler = new SchedulerAdapter {
    def execute(block: => Unit) =
      pool.execute(new Runnable {
        def run() { block }
      })
  }
} 
7
ответ дан 2 December 2019 в 20:41
поделиться

But it's quite easy to re-use the thread pool used by the actor subsystem. Firstly you can control it's size:

-Dactors.maxPoolSize=8

And you can invoke work on it:

actors.Scheduler.execute( f ); //f is => Unit

The only thing it lacks is the ability to schedule work. For this I use a separate ScheduledExecutorService which is single-threaded and runs its work on the actors thread pool:

object MyScheduler {
  private val scheduler = Executors.newSingleThreadedScheduledExecutorService

  def schedule(f: => Unit, delay: (Long, TimeUnit)) : ScheduledFuture[_] = {
      scheduler.schedule(new ScheduledRun(f), delay._1, delay._2)
  }

  private class ScheduledRun(f: => Unit) extends Runnable {
    def run = actors.Scheduler.execute(f)
  }

}

Then you can use this to schedule anything:

MyScheduler.schedule(f, (60, SECONDS))
2
ответ дан 2 December 2019 в 20:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: