Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:35:11+00:00 2026-06-13T06:35:11+00:00

The documentation says that the ValidatorFactory is thread-safe, but I have a concern about

  • 0

The documentation says that the ValidatorFactory is thread-safe, but I have a concern about using the annotated service “InvService” as shown below, as a class property.

I am wondering if this approach is thread-safe? I basically need to do a database lookup based on the constraint violation.

public class MyValidator {

    @Autowired
    InvService invService;                        //  ??????
    private final ValidatorFactory factory;


    public MyValidator() {
        factory = Validation.buildDefaultValidatorFactory();
    }


    public <T> void validate(final T instance) {
        final Validator validator = factory.getValidator();


        final Set<ConstraintViolation< T>> violations = validator.validate(instance, Default.class);

        if (!violations.isEmpty()) {
            final Set<ConstraintViolation<?>> constraints = new HashSet<ConstraintViolation<?>>(violations.size());

            for (final ConstraintViolation<?> violation : violations) {
                constraints.add(violation);
            }
            getDBRecords(constraints); 
            throw new ConstraintViolationException(constraints);
        }
    }

    private getDBRecords(Set<ConstraintViolation<?>> constraints) {
        invService.get(....);
    }
}

This is what the service class looks like:

@Service
public class InvServiceImpl implements InvService {

    @Autowired
    private InvDAO InvDAO;
    private final Logger log = LoggerFactory.getLogger(this.getClass());


    @Override
    public <T extends InvContent>  getProduct(String InvKey) {
        return InvDAO.getInvContent(InvKey, TYPEPROD, Product.class);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:35:13+00:00Added an answer on June 13, 2026 at 6:35 am

    That depends… is InvService thread-safe? If it is, then you are OK. Thread-safe classes may reference instances of other thread-safe classes as attributes and remain thread-safe themselves. But you have to be sure that the object you are referencing is thread safe. If you did not develop the class, I would want to see documentation that explicitly says it is thread-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The documentation says that execute() must be called from a UI thread. But, since
Documentation says that waypoints limit is 8 points. But I have to calculate a
The official documentation says that Your application must have a local Service to facilitate
I have a question about __class__ in python. The documentation says that __class__ is
Documentation says that waypoints limit is 8 points. But I have to draw a
i have a simple question in the objectify documentation it says that Only get(),
The documentation says that camel-spring-ws(v2.7.1) officially supports spring-ws 1.5.9, but doesn't mention spring-ws 2.0.2.RELEASE.
Android documentation says that AsyncTask postExecute() is called on the UI thread. I was
The documentation says that if I already have virtualenv installed, then pip is available
The documentation says that QDataStream writes data in system independent way, but it says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.