import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class LazyManTest {

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(50);
        // We can ignore the thread safety of ArrayList because it doesn't affect the singleton test.
        List<LazyMan> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            executorService.submit(() -> {
                LazyMan lazyMan = LazyMan.getInstance();
                list.add(lazyMan);
            });
        }
        TimeUnit.SECONDS.sleep(5L);
        Set<LazyMan> set = new HashSet<>(list);
        System.out.println("LazyMan instance -------> ");
        System.out.println(set);
        executorService.shutdown();
    }
}

