title: javax.validation.Validation multiple instantiation Vs Reusing single Validator instance
body: <p>I am using javax.validation.Validation to validate jpa entities. I am always validating against the same Entities.</p>
  
  <p>I would like to know if it is better to use one Validator for all validations or to instantiate a new Validator each time I validate.</p>
  
  <p>As well, how expensive in terms of computation is it for me to instantiate a new validator each time I would like to use it?</p>
  
  <p>Option1: instantiate new validator for each validation.</p>
  
  <pre><code>public class Validator
  {
  
      public static void main(String[] args)
      {
  
  
          //Validation1
          ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
          Validator validator = factory.getValidator();
  
          Entity entityToValidate  = new Entity();
          entityToValidate.setEmail("NOT_A_VALID_EMAIL@@@tomanyat.com");
          Set&lt;ConstraintViolation&lt;T&gt;&gt; constraintViolations =             validator.validate(entityToValidate);
  
  
  
  
  
          //Validation2 (Note that validator has been created yet a second time !! )
          Validator validator2 = factory.getValidator();
  
          Entity entityToValidate2  = new Entity();        
           entityToValidate.setEmail("NOT_A_VALID_EMAIL@@@tomanyat.com");
  
          Set&lt;ConstraintViolation&lt;T&gt;&gt; constraintViolations2 = validator2.validate(entityToValidate);
  
  
  
      }
  
  
  }
  </code></pre>
  
  <p>Option2: single validator for all validations.</p>
  
  <pre><code>public class Validator
  {
  
      public static void main(String[] args)
      {
          //Validator created only once
          ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 
          Validator validator = factory.getValidator();
  
  
          //Validation #1
          Entity entityToValidate  = new Entity();
          entityToValidate.setEmail("NOT_A_VALID_EMAIL@@@tomanyat.com");
  
          Set&lt;ConstraintViolation&lt;T&gt;&gt; constraintViolations = validator.validate(entityToValidate);
  
  
  
  
          //Validation #2     
          Entity entityToValidate2  = new Entity();
          entityToValidate.setEmail("NOT_A_VALID_EMAIL@@@tomanyat.com");
  
  
          Set&lt;ConstraintViolation&lt;T&gt;&gt; constraintViolations2 = validator .validate(entityToValidate);
  
  
  
      }
  
  
  }
  </code></pre>