title: Connecting to Spark cluster remotely
body: <p>I am trying to connect to the spark master node(remote cluster node) from my local system using a Java program. I am using the following API to connect:</p>
  
  <pre><code>    SparkConf conf = new SparkConf().setAppName("WorkCountApp").setMaster("spark://masterIP:7077");
   JavaSparkContext sc = new JavaSparkContext(conf);
  </code></pre>
  
  <p>My program tries to connect to the master but fails after some time. Below is the stacktrace:</p>
  
  <pre><code>  16/11/30 17:40:26 INFO AppClient$ClientActor: Connecting to master akka.tcp://sparkMaster@ec2-54-202-212-141.us-west-2.compute.amazonaws.com:7077/user/Master...
      16/11/30 17:40:46 ERROR SparkDeploySchedulerBackend: Application has been killed. Reason: All masters are unresponsive! Giving up.
      16/11/30 17:40:46 WARN SparkDeploySchedulerBackend: Application ID is not initialized yet.
      16/11/30 17:40:46 INFO SparkUI: Stopped Spark web UI at http://172.31.11.1:4040
      16/11/30 17:40:46 INFO DAGScheduler: Stopping DAGScheduler
      16/11/30 17:40:46 INFO SparkDeploySchedulerBackend: Shutting down all executors
      16/11/30 17:40:46 INFO SparkDeploySchedulerBackend: Asking each executor to shut down
      16/11/30 17:40:46 ERROR OneForOneStrategy: 
      java.lang.NullPointerException
  java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext
      at org.apache.spark.SparkContext.org$apache$spark$SparkContext$$assertNotStopped(SparkContext.scala:103)
  </code></pre>
  
  <p>Please help me with the same</p>