Concurrency in bean confirmation

Reading Specification for JSR-303:

Constraint validation implementation instance life cycle - undefined

The initialization method is called by the Bean validation provider before any use of the constraint implementation.

The isValid method is evaluated by the Bean Validation provider each time this value is validated. It returns false if the value is invalid; otherwise, true. isValid implementations must be thread safe.

I can’t figure it out. initialize is called before every call to isValid, and should isValid be thread safe? Does this mean that I cannot store anything at the class level during initialization to access it later from isValid? Specifically, I need an annotation instance that is passed in for initialization.

Can someone shed some light on him, please?

+3
source share
2 answers

This is not to say what initialize()should be called before each call isValid(). It can only be called once before several calls isValid()for the same annotation. For example, its javadoc says:

Initialize the validator in preparation for isValid calls .

+4
source

The method initialize()is called once for each constraint, and isValid()is called for each constraint check.

( ), isValid(), isValid(). Hibernate Validator.

, isValid() (, , isValid() ).

+3

All Articles