• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ThreadPoolExecutor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala JsonParseException类代码示例发布时间:2022-05-23
下一篇:
Scala PropertyConfigurator类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap