title: RestTemplate should be static globally declared?
body: <p>I am using Java Callable Future in my code. 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;String&gt; future = executor.submit(new Task());
  
          try {
              System.out.println("Started..");
              System.out.println(future.get(3, TimeUnit.SECONDS));
              System.out.println("Finished!");
          } catch (TimeoutException e) {
              System.out.println("Terminated!");
          }
  
          executor.shutdownNow();
      }
  }
  </code></pre>
  
  <p>Below is my <code>Task</code> class which implements the Callable interface and I need to generate URL depending on the hostname we have and then make a call to SERVERS using <code>RestTemplate</code>. If there is any exception in the first hostname, then I will generate URL for another hostname and I will try making a call.</p>
  
  <pre><code>class Task implements Callable&lt;String&gt; {
      private static RestTemplate restTemplate = new RestTemplate();
  
      @Override
      public String call() throws Exception {
  
      //.. some code
  
      for(String hostname : hostnames)  {
              if(hostname == null) {
                  continue;
              }
              try {
                  String url = generateURL(hostname);         
                  response = restTemplate.getForObject(url, String.class);
  
                  // make a response and then break
                  break;
  
              } catch (Exception ex) {
                  ex.printStackTrace(); // use logger
              }
          }
      }
  }
  </code></pre>
  
  <p>So my question should I declare <code>RestTemplate</code> as static global variable? Or it should not be static in this scenario?</p>