Concurrency in bean validation
bean-validation, java
Solution
It doesn't say that `initialize()` should be called before each call of `isValid()`. It can be called only once before multiple calls of `isValid()` for the same annotation. For example, its javadoc says:
Initialize the validator in preparation for isValid calls.
Problem
Reading the spec for JSR-303 : The life cycle of a constraint validation implementation instance is undefined The initialize method is called by the Bean validation provider prior to any use of the constraint implementation. The isValid method is evaluated by the Bean Validation provider each time a given value is validated. It returns false if the value is not valid, true otherwise. isValid implementations must be thread-safe. I cannot quite understand it. initialize is called prior to each isValid call, and isValid should be thread safe? Does it mean I cannot store anything in class level in initialize to access it later from isValid? Specially I need the annotation instance that is passed to initialize. Can somebody shed light on it please?