本文整理汇总了Scala中java.util.concurrent.ThreadPoolExecutor类的典型用法代码示例。如果您正苦于以下问题:Scala ThreadPoolExecutor类的具体用法?Scala ThreadPoolExecutor怎么用?Scala ThreadPoolExecutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadPoolExecutor类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Message
//设置package包名称以及导入依赖的类
package com.twitter.diffy.lifter
import com.twitter.concurrent.NamedPoolThreadFactory
import com.twitter.util.{ExecutorServiceFuturePool, Future, FuturePool}
import java.util.concurrent.{ArrayBlockingQueue, ThreadPoolExecutor, TimeUnit}
case class Message(endpoint: Option[String], result: FieldMap[Any])
trait MapLifter {
def apply(input: Array[Byte]): Future[Message]
}
object MapLifterPool {
val QueueSizeDefault = 5
def apply(mapLifterFactory: => MapLifter) = {
val executorService =
new ThreadPoolExecutor(
3, // core pool size
10, // max pool size
500, // keep alive time
TimeUnit.MILLISECONDS,
new ArrayBlockingQueue[Runnable](10), // work queue
new NamedPoolThreadFactory("maplifter", makeDaemons = true),
new ThreadPoolExecutor.AbortPolicy()
)
executorService.prestartCoreThread()
new MapLifterPool(mapLifterFactory, new ExecutorServiceFuturePool(executorService))
}
}
class MapLifterPool(underlying: MapLifter, futurePool: FuturePool) extends MapLifter {
override def apply(input: Array[Byte]): Future[Message] =
(futurePool { underlying(input) }).flatten
}
开发者ID:sachinmanchanda,项目名称:diffy_unicast,代码行数:36,代码来源:MapLifter.scala
示例2: MudBot
//设置package包名称以及导入依赖的类
package org.kirhgoff.munchkin
import java.net.Socket
import java.util.concurrent.Executors._
import java.util.concurrent.ThreadPoolExecutor
class MudBot(hostname: String, port: Int) {
val executor:ThreadPoolExecutor =
newFixedThreadPool(2).asInstanceOf[ThreadPoolExecutor]
val socket = new Socket(hostname, port)
val outputStream = socket.getOutputStream
val inputStream = socket.getInputStream
def stop() = {
try { inputStream.close() } catch { case e:Exception => e.printStackTrace()}
try { outputStream.close() } catch { case e:Exception => e.printStackTrace()}
try { socket.close() } catch { case e:Exception => e.printStackTrace()}
}
def startLoop() = {
val writer = new MudWriter(outputStream)
val ai = new FalloutBot (writer)
val inputReader = new UserInputReader(ai)
val reader = new MudReader(inputStream, ai)
executor.execute(reader)
executor.execute(inputReader)
while (executor.getActiveCount == 2) {
Thread.sleep(1000)
}
println("system> Exiting")
executor.shutdownNow()
System.exit(0)
}
//def enterWarzone(): Unit = ???
//def login(login: String, passwordPath: String): Unit = ???
}
开发者ID:kirhgoff,项目名称:munchkin,代码行数:43,代码来源:MudBot.scala
示例3: Test
//设置package包名称以及导入依赖的类
package teleporter.stream.integration.transaction
import java.util.concurrent.{LinkedBlockingQueue, ThreadPoolExecutor, TimeUnit}
object Test extends App {
val pool = new ThreadPoolExecutor(2, 20, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue[Runnable](1))
for (i ? 1 to 10) {
pool.execute(new Runnable {
override def run(): Unit = {
while (true) {
println(s"${Thread.currentThread().getName}: $i")
Thread.sleep(2000)
}
}
})
}
}
开发者ID:huanwuji,项目名称:teleporter,代码行数:19,代码来源:Test.scala
示例4: AsyncProcessor
//设置package包名称以及导入依赖的类
package alexsmirnov.stream
import java.util.concurrent.Executors
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import org.reactivestreams.Processor
import java.util.concurrent.LinkedBlockingQueue
class AsyncProcessor[A](queueSize: Int = 100) extends Processor[A, A] with PublisherBase[A] with SubscriberBase[A] {
private[this] val executor = Executors.unconfigurableExecutorService(
new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue[Runnable](queueSize + 1),
streamsThreadFactory))
def onStart() { request(queueSize) }
def onStop() { cancel() }
def onNext(a: A) {
executor.submit(new Runnable { def run() { sendNext(a); request(1L) } })
}
def onComplete() = {
executor.submit(new Runnable { def run() { sendComplete() } })
}
def onError(t: Throwable) {
stopProducer()
sendError(t)
}
}
开发者ID:alexsmirnov,项目名称:printrbot-g2-console,代码行数:30,代码来源:AsyncProcessor.scala
注:本文中的java.util.concurrent.ThreadPoolExecutor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论