How to do it...

Follow these steps to implement the example:

  1. Create a class named UserValidator that will implement the process of user validation:
        public class UserValidator {
  1. Declare a private String attribute called name that will store the name of the user validation system:
        private final String name;
  1. Implement the constructor of the class that initializes its attributes:
        public UserValidator(String name) { ;         }
  1. Implement the validate() method. It receives two String parameters with the name and password of the user you want to validate:
        public boolean validate(String name, String password) {
  1. Create a Random object named random:
        Random random=new Random();
  1. Wait for a random period of time to simulate ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.