scala class和object的區別

破棉襖發表於2015-10-21

Scala中類物件中不可有靜態變數和靜態方法,但是提供了“伴侶物件”的功能:在和類的同一個檔案中定義同名的Object物件:(須在同一檔案中;main方法定義在Object物件中)

  1. private[spark] class Client(
  2.     val args: ClientArguments,
  3.     val hadoopConf: Configuration,
  4.     val sparkConf: SparkConf)
  5.   extends Logging {...}

  6. object Client extends Logging {
  7.   def main(argStrings: Array[String]) {
  8.     if (!sys.props.contains("SPARK_SUBMIT")) {
  9.       logWarning("WARNING: This client is deprecated and will be removed in a " +
  10.         "future version of Spark. Use ./bin/spark-submit with \"--master yarn\"")
  11.     }

  12.     // Set an env variable indicating we are running in YARN mode.
  13.     // Note that any env variable with the SPARK_ prefix gets propagated to all (remote) processes
  14.     System.setProperty("SPARK_YARN_MODE", "true")
  15.     val sparkConf = new SparkConf

  16.     val args = new ClientArguments(argStrings, sparkConf)
  17.     // to maintain backwards-compatibility
  18.     if (!Utils.isDynamicAllocationEnabled(sparkConf)) {
  19.       sparkConf.setIfMissing("spark.executor.instances", args.numExecutors.toString)
  20.     }
  21.     new Client(args, sparkConf).run()
  22.   }
  23.  ......
  24. }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29754888/viewspace-1815301/,如需轉載,請註明出處,否則將追究法律責任。

相關文章