@Test
public void multiThread() throws InterruptedException {

    int threads = 64;
    final int idsNum = 10000;
    final IdGeneratorService service = new IdGeneratorService();
    ExecutorService executorService = newFixedThreadPool(threads * 2);
    final CountDownLatch latch = new CountDownLatch(threads);
    final ConcurrentHashMap<Long, Boolean> ids = new ConcurrentHashMap<>();
    for (int i = 0; i < threads; i++) {
        executorService.submit(
                new Runnable() {
                    @Override
                    public void run() {
                        try {
                            for (int j = 0; j < idsNum; j++) {
                                long id = service.generate(1);
                                if (null != ids.putIfAbsent(id, true)) {
                                    throw new RuntimeException("" + id);
                                }
                            }
                        } catch (Exception e) {
                            log.error("Exception", e);
                        } finally {
                            latch.countDown();
                        }
                    }
                }
        );
    }
    latch.await();
    assertEquals(ids.size(), threads * idsNum);
}