title: The performance impact of use System.getenv() in java
body: <p>I have a REST web service in java built with jersey and for security reasons I would like to save in the OS environment variables the parameters of the method: <code>DriverManager.getConnection();</code>. Url, username and password.</p>
  
  <p>Since every request needs to create his own connection I want to know if so many calls to <code>System.getenv("key");</code> are a performance problem?</p>
  
  <p>The idea of doing so is from this article: <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-rds.html#java-rds-javase" rel="nofollow noreferrer">http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-rds.html#java-rds-javase</a></p>
  
  <p>Would be a better option to have something like this:</p>
  
  <pre><code>public class EnvironmentHelper {
      static final String URL;
      static final String USERNAME;
      static final String PASSWORD;
  
      static {
          URL = System.getenv("URL");
          USERNAME = System.getenv("USERNAME");
          PASSWORD = System.getenv("PASSWORD");
      }
  }
  </code></pre>
  
  <p>This way I only load the variables once, right? No matter how many requests I receive.</p>