Spark-futureAction

本文主要探讨了Spark中的FutureAction,包括SimpleFutureAction,其核心是JobWaiter监听器实现取消功能,JavaFutureActionWrapper对JavaFutureAction的封装,以及更复杂的ComplexFutureAction。同时提到了Scala的Promise和Future的相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spark-futureAction

@(spark)[FutureAction]

FutureAction

 * A future for the result of an action to support cancellation. This is an extension of the                                                                            
 * Scala Future interface to support cancellation.                                                                                                                      
 */                                                                                                                                                                     
trait FutureAction[T] extends Future[T] { 

SimpleFutureAction

/**                                                                                                                                                                     
 * A [[FutureAction]] holding the result of an action that triggers a single job. Examples include                                                                      
 * count, collect, reduce.                                                                                                                                              
 */                                                                                                                                                                     
class SimpleFutureAction[T] private[spark](jobWaiter: JobWaiter[_], resultFunc: => T)   
  1. SimpleFutureAction的核心实际上是那个叫做JobWaiter,它本身是个listener。
  2. cancel也是通过JobWaiter实现的

JavaFutureActionWrapper

就是对JavaFutureAction的封装

ComplexFutureAction

/**                                                                                                                                                                     
 * A [[FutureAction]] for actions that could trigger multiple Spark jobs. Examples include take,                                                                        
 * takeSample. Cancellation works by setting the cancelled flag to true and interrupting the                                                                            
 * action thread if it is being blocked by a job.                                                                                                                       
 */                                                                                                                                                                     
class ComplexFutureAction[T] extends FutureAction[T] {    

关于scala的promise和future,请参考
基本上就是runJob之后就一直block。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值