@Test public synchronized void performance() throws InterruptedException { final String[][] results = new String[concurrency][]; Thread[] threads = new Thread[concurrency]; for (int i = 0; i < concurrency; i++) { final String[] result = new String[loop]; results[i] = result; threads[i] = new Thread(new Runnable() { public void run() { for (int i = 0; i < loop; i++) { result[i] = uuid.nextID(); } } }, "t-" + (i + 1)); } long start = System.currentTimeMillis(); for (Thread thread : threads) { thread.start(); } for (Thread thread : threads) { thread.join(); } long duration = System.currentTimeMillis() - start; System.out.printf("%s: requests=%d, concurrency=%d%n", uuid.getClass().getSimpleName(), concurrency * loop, concurrency); System.out.printf(" Total time: %,d ms.%n", duration); System.out.printf("Average time: %,2.2f \u03BCs.%n", (double) duration / concurrency / loop * 1000); Set<String> allIDs = CollectionUtil.createHashSet(); for (String[] result : results) { for (String id : result) { assertNotNull(id); assertTrue(id, !id.contains("+") && !id.contains("/") && !id.contains("=")); allIDs.add(id); } } assertEquals(concurrency * loop, allIDs.size()); }
public String nextID() { return instanceId + "-" + StringUtil.longToString(System.currentTimeMillis(), noCase) + "-" + StringUtil.longToString(counter.getAndIncrement(), noCase); }
UUID { public String nextID() { return instanceId + "-" + StringUtil.longToString(System.currentTimeMillis(), noCase) + "-" + StringUtil.longToString(counter.getAndIncrement(), noCase); } }
UUID { public String nextID() { return instanceId + "-" + StringUtil.longToString(System.currentTimeMillis(), noCase) + "-" + StringUtil.longToString(counter.getAndIncrement(), noCase); } UUID();  UUID(boolean noCase); }
UUID { public String nextID() { return instanceId + "-" + StringUtil.longToString(System.currentTimeMillis(), noCase) + "-" + StringUtil.longToString(counter.getAndIncrement(), noCase); } UUID();  UUID(boolean noCase); String nextID(); }
UUID { public String nextID() { return instanceId + "-" + StringUtil.longToString(System.currentTimeMillis(), noCase) + "-" + StringUtil.longToString(counter.getAndIncrement(), noCase); } UUID();  UUID(boolean noCase); String nextID();  }