title: Loading class which have only static methods
body: <p>I have a class <code>MyClass</code> that has a static variable. Class implements smth like singleton(it has <code>java.sql.DataSource</code> as static variable and has method <code>getConnection()</code> which checks whether DataSource variable is not null and if it is null - obtains the connection, else - return <code>dataSource.getConnection()</code>) 
  When I call <code>MyClass.getConnection()</code> method for the first time the class is loaded to the memory and DataSource variable is obtained. Will this class stay in memory while the program is running or it will be garbage collected when the control flow of the program will exit outside the method where  <code>MyClass.getConnection()</code> was invoked?
  Actually I want to know whether I have to obtain Connection object in each method(obtaining connection object is rather long operation, isn't it?) where I use it or only once in some place? </p>
  
  <p><strong>edit</strong>
  This is my class that obtains a connection</p>
  
  <pre><code>public class ResourceManager {
  
      private static DataSource dataSource;
  
  
      public static synchronized Connection getConnection() throws NamingException, SQLException {
          if (dataSource == null) {
              Locale.setDefault(Locale.ENGLISH);
              Context context = (Context) new InitialContext().lookup("java:comp/env");
              dataSource = (DataSource) context.lookup("jdbc/Project");
              context.close();
          }
          return dataSource.getConnection();
      }
  
  
      public static void close(Connection con) {
          if (con != null)
              try {
              con.close();
          } catch (SQLException ex) {
              Logger.getLogger(ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  
      public static void close(ResultSet rs) {
          if (rs != null)
              try {
              rs.close();
          } catch (SQLException ex) {
              Logger.getLogger(ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
  
      public static void close(PreparedStatement stmt) {
          if (stmt != null)
              try {
              stmt.close();
          } catch (SQLException ex) {
              Logger.getLogger(ResourceManager.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p>in this class I obtain connection from tomcat pool</p>
  
  <p>So, if in one method I call ResourseManager.getConnection() and it obtains the datasource, will it be the same datasource when I call this method after some time passed or it will be GC?</p>
  
  <p>P.S. I use close methods in finally blocks</p>