Skip to content

Commit 270cfe3

Browse files
author
Ilya Ganelin
committed
[SPARK-6703] Documentation fixes
1 parent 15e8dea commit 270cfe3

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

core/src/main/scala/org/apache/spark/SparkContext.scala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,23 +1857,31 @@ object SparkContext extends Logging {
18571857
}
18581858

18591859
/**
1860-
* Because we can only have one active Spark Context per JVM and there are times when multiple
1861-
* applications may wish to share a SparkContext, this function may be used to get or instantiate
1862-
* a SparkContext and register it as a singleton object.
1860+
* This function may be used to get or instantiate a SparkContext and register it as a
1861+
* singleton object. Because we can only have one active SparkContext per JVM,
1862+
* this is useful when applications may wish to share a SparkContext.
18631863
*
1864-
* Note: This function cannot be used to create multiple spark contexts even if multiple contexts
1865-
* are allowed. Multiple contexts will still need to be created with explicit calls to the
1866-
* SparkContext constructor.
1864+
* Note: This function cannot be used to create multiple SparkContexts even if multiple contexts
1865+
* are allowed.
18671866
*/
18681867
def getOrCreate(config: SparkConf): SparkContext = {
1869-
if (activeContext.get() != null) {
1868+
if (activeContext.get() == null) {
18701869
setActiveContext(new SparkContext(config),
18711870
config.getBoolean("spark.driver.allowMultipleContexts", false))
18721871
}
18731872
activeContext.get()
18741873
}
18751874

1876-
/** Allow not passing a SparkConf (useful if just retrieving) */
1875+
/**
1876+
* This function may be used to get or instantiate a SparkContext and register it as a
1877+
* singleton object. Because we can only have one active SparkContext per JVM,
1878+
* this is useful when applications may wish to share a SparkContext.
1879+
*
1880+
* This method allows not passing a SparkConf (useful if just retrieving)
1881+
*
1882+
* Note: This function cannot be used to create multiple SparkContexts even if multiple contexts
1883+
* are allowed.
1884+
*/
18771885
def getOrCreate(): SparkContext = {
18781886
getOrCreate(new SparkConf())
18791887
}

core/src/test/scala/org/apache/spark/SparkContextSuite.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ class SparkContextSuite extends FunSuite with LocalSparkContext {
6767
}
6868
}
6969

70-
test("Test getOrCreateContext") {
70+
test("Test getOrCreate") {
7171
var sc2: SparkContext = null
7272
SparkContext.clearActiveContext()
7373
val conf = new SparkConf().setAppName("test").setMaster("local")
74-
.set("spark.driver.allowMultipleContexts", "true")
7574

7675
sc = SparkContext.getOrCreate(conf)
7776

0 commit comments

Comments
 (0)