### Question:
DefaultKeyGenerator implements KeyGenerator { @Override public synchronized Number generateKey() { long currentMillis = timeService.getCurrentMillis(); Preconditions.checkState(lastTime <= currentMillis, "Clock is moving backwards, last time is %d milliseconds, current time is %d milliseconds", lastTime, currentMillis); if (lastTime == currentMillis) { if (0L == (sequence = ++sequence & SEQUENCE_MASK)) { currentMillis = waitUntilNextTime(currentMillis); } } else { sequence = 0; } lastTime = currentMillis; if (log.isDebugEnabled()) { log.debug("{}-{}-{}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(lastTime)), workerId, sequence); } return ((currentMillis - EPOCH) << TIMESTAMP_LEFT_SHIFT_BITS) | (workerId << WORKER_ID_LEFT_SHIFT_BITS) | sequence; }  static void setWorkerId(final long workerId); @Override synchronized Number generateKey(); static final long EPOCH; }### Answer:
@Test public void assertGenerateKey() throws Exception { int threadNumber = Runtime.getRuntime().availableProcessors() << 1; ExecutorService executor = Executors.newFixedThreadPool(threadNumber); final int taskNumber = threadNumber << 2; final DefaultKeyGenerator keyGenerator = new DefaultKeyGenerator(); Set<Number> generatedKeys = new HashSet<>(); for (int i = 0; i < taskNumber; i++) { generatedKeys.add(executor.submit(new Callable<Number>() { @Override public Number call() throws Exception { return keyGenerator.generateKey(); } }).get()); } assertThat(generatedKeys.size(), is(taskNumber)); }