title: spark - SparkContext and SqlContext - lifecycle and threadsafty
body: <p>I am developing rest services top of spark which takes user query as input, formulate spark sql and execute it on spark cluster. Here's what my assumption with JavaSparkContext and JavaSqlContext: <br/>
  1) They both threadsafe
  2) I can reuse single instance throughout application(Context!)</p>
  
  <p>Based on this I initialize only one instance of these variables during application startup and then tries to reuse them for all incoming request. <br/></p>
  
  <p>I can fire request and get results as expected but what I found recently is my application dies if it's been idle for several minutes with following exception. <br/>
  <code>11:49:50.475 [spark-akka.actor.default-dispatcher-14] ERROR o.a.s.s.c.SparkDeploySchedulerBackend- Application has been killed. Reason: Master removed our application: FAILED<br>
  11:49:50.477 [spark-akka.actor.default-dispatcher-14] ERROR o.a.s.scheduler.TaskSchedulerImpl- Exiting due to error from cluster scheduler: Master removed our application: FAILED</code></p>
  
  <p>So am I wrong with any of my assumption that led me to this issue or wrong with design in general? </p>