本文介绍了如何在Akka调度程序中使用自定义执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Akka中为调度程序使用自定义执行程序。
I am trying to use a custom executor for a dispatcher in Akka.
特别是,我想用我自己的包装现有执行程序(记录,调试等)。 。
Specifically, I want to wrap an existing executor with my own (logging, debugging, etc.).
我看过:
和
(我不知道什么是FQCN。)
(I don't understand what FQCN is.)
我该怎么办
推荐答案
FQCN ==完全合格的类名,即包名+类名,例如:
FQCN == Fully Qualified Class Name i.e. package name(s) + class name, ex:
java.lang.String< -字符串的FQCN
java.lang.String <- FQCN for String
以下是内置ThreadPoolExecutor的ExecutorServiceConfigurator的示例:
Here's an example of an ExecutorServiceConfigurator for the built in ThreadPoolExecutor:
class ThreadPoolExecutorConfigurator(config: Config, prerequisites: DispatcherPrerequisites) extends ExecutorServiceConfigurator(config, prerequisites) {
val threadPoolConfig: ThreadPoolConfig = createThreadPoolConfigBuilder(config, prerequisites).config
protected def createThreadPoolConfigBuilder(config: Config, prerequisites: DispatcherPrerequisites): ThreadPoolConfigBuilder = {
import akka.util.Helpers.ConfigOps
ThreadPoolConfigBuilder(ThreadPoolConfig())
.setKeepAliveTime(config.getMillisDuration("keep-alive-time"))
.setAllowCoreThreadTimeout(config getBoolean "allow-core-timeout")
.setCorePoolSizeFromFactor(config getInt "core-pool-size-min", config getDouble "core-pool-size-factor", config getInt "core-pool-size-max")
.setMaxPoolSizeFromFactor(config getInt "max-pool-size-min", config getDouble "max-pool-size-factor", config getInt "max-pool-size-max")
.configure(
Some(config getInt "task-queue-size") flatMap {
case size if size > 0 ⇒
Some(config getString "task-queue-type") map {
case "array" ⇒ ThreadPoolConfig.arrayBlockingQueue(size, false) //TODO config fairness?
case "" | "linked" ⇒ ThreadPoolConfig.linkedBlockingQueue(size)
case x ⇒ throw new IllegalArgumentException("[%s] is not a valid task-queue-type [array|linked]!" format x)
} map { qf ⇒ (q: ThreadPoolConfigBuilder) ⇒ q.setQueueFactory(qf) }
case _ ⇒ None
})
}
def createExecutorServiceFactory(id: String, threadFactory: ThreadFactory): ExecutorServiceFactory =
threadPoolConfig.createExecutorServiceFactory(id, threadFactory)
}
来源:
这篇关于如何在Akka调度程序中使用自定义执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!