今晚听了王家林老师的Spark 3000门徒系列第五课scala隐式转换和并发编程,课后作业是:分析DAGScheduler Master Worker RDD源码中隐式转换和Actor并发编程,我的见解如下:
隐式函数,隐式参数最常见,隐式对象和隐式类少见
RDD中方法:
def distinct(numPartitions: Int)(implicit ord: Ordering[T] = null): RDD[T] = withScope {
map(x => (x, null)).reduceByKey((x, y) => x, numPartitions).map(_._1)
}
使用了隐式参数,运行时不需要手动提供参数ord,运行时会根据上下文注入参数
最简单的actor并发编程:
import scala.actors.Actor
class HiActor extends Actor{
def act(){
while(true){
receive{
case name:String => println(name)
}
}
}
}
调用:actor ! "Spark"
后续课程可以参照王家林_DT大数据梦工厂:http://weibo.com/ilovepains