title: Should GSON be declared as static final?
body: <p>I am using Java Callable Future in my code. Below is my main code which uses the future and callables -</p>
  
  <p>Below is my main code which uses the future and callables -</p>
  
  <pre><code>public class TimeoutThread {
  
      public static void main(String[] args) throws Exception {
  
          ExecutorService executor = Executors.newFixedThreadPool(5);
          Future&lt;TestResponse&gt; future = executor.submit(new Task());
  
          try {
              System.out.println(future.get(3, TimeUnit.SECONDS));
          } catch (TimeoutException e) {
  
          }
  
          executor.shutdownNow();
      }
  }
  </code></pre>
  
  <p>Below is my <code>Task</code> class which implements the Callable interface in which I am making a REST URL call to my SERVERS using <code>RestTemplate</code>. And then I am passing <code>response</code> variable to <code>checkString</code> method in which I am deserializing the JSON string and then I am checking whether the key has <code>error</code> or <code>warning</code> in it and then basis on that make a <code>TestResponse</code>.</p>
  
  <pre><code>class Task implements Callable&lt;TestResponse&gt; {
      private static RestTemplate restTemplate = new RestTemplate();
  
      @Override
      public TestResponse call() throws Exception {
  
      String url = "some_url";            
      String response = restTemplate.getForObject(url, String.class);
  
      TestResponse response = checkString(response);
      }
  }
  
  private TestResponse checkString(final String response) throws Exception {
  
      Gson gson = new Gson(); // is this an expensive call here, making objects for each and every call?
      TestResponse testResponse = null;
      JsonObject jsonObject = gson.fromJson(response, JsonObject.class); // parse, need to check whether it is an expensive call or not.
      if (jsonObject.has("error") || jsonObject.has("warning")) {
  
          final String error = jsonObject.get("error") != null ? jsonObject.get("error").getAsString() : jsonObject
              .get("warning").getAsString();
  
          testResponse = new TestResponse(response, "NONE", "SUCCESS");
      } else {
          testResponse = new TestResponse(response, "NONE", "SUCCESS");
      }
  
      return testResponse;
  }
  </code></pre>
  
  <p>So my question is how should I declare <code>GSON</code> here? Should it be declared as static final global variable in my Task class? Bcoz currently I am parsing JSON using gson and for every call I am making <code>new Gson()</code> which would be expensive or not?</p>