Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Created February 28, 2011 15:27
Show Gist options
  • Save mpilquist/847465 to your computer and use it in GitHub Desktop.
Save mpilquist/847465 to your computer and use it in GitHub Desktop.
Example of using custom executor with Akka 1.0
import java.util.concurrent.ExecutorService
import java.util.concurrent.atomic.AtomicReference
import akka.dispatch.ExecutorBasedEventDrivenDispatcher
import akka.dispatch.Dispatchers
import akka.dispatch.MailboxType
abstract class ExecutorDispatcher(
name: String,
throughput: Int = Dispatchers.THROUGHPUT,
throughputDeadlingTime: Int = Dispatchers.THROUGHPUT_DEADLINE_TIME_MILLIS,
mailboxType: MailboxType = Dispatchers.MAILBOX_TYPE)
extends ExecutorBasedEventDrivenDispatcher(name, throughput, throughputDeadlingTime, mailboxType) {
override val executorService = new AtomicReference[ExecutorService](createExecutor)
override def shutdown {
val old = executorService.getAndSet(createExecutor)
if (old != null) {
old.shutdownNow
}
}
protected def createExecutor: ExecutorService
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment