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

Scala ForkJoinPool类代码示例

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

本文整理汇总了Scala中scala.concurrent.forkjoin.ForkJoinPool的典型用法代码示例。如果您正苦于以下问题:Scala ForkJoinPool类的具体用法?Scala ForkJoinPool怎么用?Scala ForkJoinPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ForkJoinPool类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: EventClientActor

//设置package包名称以及导入依赖的类
package com.bob.scalatour.akka.cluster

import akka.actor.{Props, ActorSystem, ActorRef, Actor}
import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._

import scala.concurrent.ExecutionContext
import scala.concurrent.forkjoin.ForkJoinPool


class EventClientActor extends Actor {

  implicit val ec: ExecutionContext = ExecutionContext.fromExecutor(new ForkJoinPool())

  val events = Map(

    "2751" -> List(
      """10.10.2.72 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000lAOX&udid=25371384b2eb1a5dc5643e14626ecbd4&sessionid=25371384b2eb1a5dc5643e14626ecbd41440152875362&imsi=460002830862833&operator=1&network=1&timestamp=1440152954&action=14&eventcode=300039&page=200002& HTTP/1.0" "-" 204 0 "-" "Dalvik/1.6.0 (Linux; U; Android 4.4.4; R8207 Build/KTU84P)" "121.25.190.146"""",
      """10.10.2.8 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000VACO&udid=f6b0520cbc36fda6f63a72d91bf305c0&imsi=460012927613645&operator=2&network=1&timestamp=1440152956&action=1840&eventcode=100003&type=1&result=0& HTTP/1.0" "-" 204 0 "-" "Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9500 Build/KOT49H)" "61.175.219.69""""
    ),

    "2752" -> List(
      """10.10.2.72 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000gCo4&udid=636d127f4936109a22347b239a0ce73f&sessionid=636d127f4936109a22347b239a0ce73f1440150695096&imsi=460036010038180&operator=3&network=4&timestamp=1440152902&action=1566&eventcode=101010&playid=99d5a59f100cb778b64b5234a189e1f4&radioid=1100000048450&audioid=1000001535718&playtime=3& HTTP/1.0" "-" 204 0 "-" "Dalvik/1.6.0 (Linux; U; Android 4.4.4; R8205 Build/KTU84P)" "106.38.128.67"""",
      """10.10.2.72 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000kPSC&udid=2ee585cde388ac57c0e81f9a76f5b797&operator=0&network=1&timestamp=1440152968&action=6423&eventcode=100003&type=1&result=0& HTTP/1.0" "-" 204 0 "-" "Dalvik/v3.3.85 (Linux; U; Android L; P8 Build/KOT49H)" "202.103.133.112"""",
      """10.10.2.72 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000lABW&udid=face1161d739abacca913dcb82576e9d&sessionid=face1161d739abacca913dcb82576e9d1440151582673&operator=0&network=1&timestamp=1440152520&action=1911&eventcode=101010&playid=b07c241010f8691284c68186c42ab006&radioid=1100000000762&audioid=1000001751983&playtime=158& HTTP/1.0" "-" 204 0 "-" "Dalvik/1.6.0 (Linux; U; Android 4.1; H5 Build/JZO54K)" "221.232.36.250""""
    ),

    "2753" -> List(
      """10.10.2.8 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000krJw&udid=939488333889f18e2b406d2ece8f938a&sessionid=939488333889f18e2b406d2ece8f938a1440137301421&imsi=460028180045362&operator=1&network=1&timestamp=1440152947&action=1431&eventcode=300030&playid=e1fd5467085475dc4483d2795f112717&radioid=1100000001123&audioid=1000000094911&playtime=951992& HTTP/1.0" "-" 204 0 "-" "Dalvik/1.6.0 (Linux; U; Android 4.0.4; R813T Build/IMM76D)" "5.45.64.205"""",
      """10.10.2.72 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000kcpz&udid=cbc7bbb560914c374cb7a29eef8c2144&sessionid=cbc7bbb560914c374cb7a29eef8c21441440152816008&imsi=460008782944219&operator=1&network=1&timestamp=1440152873&action=360&eventcode=200003&page=200003&radioid=1100000046018& HTTP/1.0" "-" 204 0 "-" "Dalvik/v3.3.85 (Linux; U; Android 4.4.2; MX4S Build/KOT49H)" "119.128.106.232"""",
      """10.10.2.8 [21/Aug/2015:18:29:19 +0800] "GET /t.gif?installid=0000juRL&udid=3f9a5ffa69a5cd5f0754d2ba98c0aeb2&imsi=460023744091238&operator=1&network=1&timestamp=1440152957&action=78&eventcode=100003&type=1&result=0& HTTP/1.0" "-" 204 0 "-" "Dalvik/v3.3.85 (Linux; U; Android 4.4.3; S?MSUNG. Build/KOT49H)" "223.153.72.78""""
    )
  )

  val ports = Seq("2751", "2752", "2753")
  val actors = scala.collection.mutable.HashMap[String, ActorRef]()
  ports.foreach(port => {
    val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port=${port}")
      .withFallback(ConfigFactory.parseString("akka.cluster.roles = [collector]"))
      .withFallback(ConfigFactory.load())
    val system = ActorSystem("event-cluster-system", config)
    actors(port) = system.actorOf(Props[EventCollector], name = "collectingActor")
  })

  Thread.sleep(30000)
  context.system.scheduler.schedule(0 millis, 5000 millis) {
    ports.foreach(port => {
      events(port).foreach(line => {
        println("RAW: port=" + port + ", line=" + line)
        actors(port) ! RawNginxRecord("host.me:" + port, line)
      })
    })
  }

  override def receive: Receive = {
    case _ =>
  }
} 
开发者ID:bobxwang,项目名称:scalatour,代码行数:59,代码来源:EventClientActor.scala


示例2: SForkJoin

//设置package包名称以及导入依赖的类
package com.bob.scalatour.sthread

import scala.concurrent.forkjoin.{ForkJoinPool, RecursiveTask}



object SForkJoin {

  class CountTask(start: Int, end: Int) extends RecursiveTask[Int] {

    val MAX = 1000

    override def compute(): Int = {
      val conCompute = (end - start) <= MAX
      conCompute match {
        case true => {
          (start to end).sum
        }
        case false => {
          val middle = (start + end) / 2
          val task1 = new CountTask(start, middle)
          val task2 = new CountTask(middle + 1, end)
          task1.fork()
          task2.fork()
          task1.join() + task2.join()
        }
      }
    }
  }

  def main(args: Array[String]) {

    val forkJoinPool = new ForkJoinPool()
    val task = new CountTask(1, 10000)
    val rs = forkJoinPool.submit(task)
    println(rs.get())
    if (task.isCompletedAbnormally) {
      println(task.getException)
    }
    forkJoinPool.shutdown()
  }
} 
开发者ID:bobxwang,项目名称:scalatour,代码行数:43,代码来源:SForkJoin.scala


示例3: Main3

//设置package包名称以及导入依赖的类
package de.trash

import scala.concurrent.forkjoin.ForkJoinPool
import scala.collection.parallel.ForkJoinTaskSupport
import scala.util.control.Breaks._
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.atomic.AtomicBoolean
import scala.BigInt

object Main3 extends App {
  
  val clauses = List[List[Short]](List(3,3,3),List(2,1,-1),List(-3,-2,-3),List(2,1,2))
  //println(clauses.transpose)
  
  val nVar : Int = 3
  
  
  var i : Int =0;
  val iVar = (for {i <- 0 until nVar} yield Math.pow(2, i).toLong)
  val maxNumber = BigInt(Math.pow(2, nVar).toLong)
  var number: AtomicLong = new AtomicLong(0)
	var end: AtomicBoolean = new AtomicBoolean(false)
  
	val fjpool = new ForkJoinPool(1)
  val customTaskSupport = new ForkJoinTaskSupport(fjpool)
  
	val t = (BigInt(0) to BigInt(maxNumber+""))
	//t.tasksupport = customTaskSupport
	
	t.foreach({ x => {
	  
    if(!end.get()){
      if({
        clauses.forall({ c => {
          println(c+" "+x)
          if(x.toLong==4){
            println("yap")
          }
          !(0 to 2).forall({ i => {
    	      val v : Int = c(i)
    	      println(v)
    	      if(v>0){
    	        println(iVar(v - 1))
    	      }else if(v<0){
    	        println(iVar(-v - 1)) 
    	      } 
    	      var ret = true
    	      !(v > 0 && (x.toLong & iVar(v - 1)) > 0) && !(v < 0 && (x.toLong & iVar(-v - 1)) == 0)
    	      
  
  
} 
开发者ID:Mashashi,项目名称:7thMarathonParallelProgramming,代码行数:53,代码来源:backup2_Main.scala



注:本文中的scala.concurrent.forkjoin.ForkJoinPool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Charsets类代码示例发布时间:2022-05-23
下一篇:
Scala ForkJoinTaskSupport类代码示例发布时间: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