首页 > 解决方案 > 在单个 JVM 中运行多个 SparkContext,或在 intellij env 中创建多个 JVM

问题描述

我想在 Intellij 中创建一个本地 spark 环境,用于维护多个本地 spark 会话的 Spark 应用程序的开发/测试,每个执行者一个。

所以,我的开发者。环境应允许在单个 JVM 上使用多个 sparkContext 或运行多个 JVM,以模拟执行程序及其本地会话。

你能为此目的推荐任何可能的方法吗?

以下是我的代码和错误。

val conf = new SparkConf().setAppName("Testing")
     .setMaster("local-cluster[8, 2, 128]") // or .setMaster("local[*]")
     .set("spark.driver.allowMultipleContexts", "true")

val sc: SparkContext = new SparkContext(conf)



[Executor task launch worker for task 2] WARN  org.apache.spark.SparkContext:    
   Multiple running SparkContexts detected in the same JVM!
org.apache.spark.SparkException: Only one SparkContext may be running in this JVM (see SPARK-2243). 
   To ignore this error, set spark.driver.allowMultipleContexts = true. 
   The currently running SparkContext was created at:
org.apache.spark.SparkContext.<init>(SparkContext.scala:126)```


标签: scalaapache-spark

解决方案


推荐阅读