05-14-2012 10:58 AM
final TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
final Set<UUID> ids = new HashSet<UUID>();
Runnable r = new Runnable() {
public void run() {
for (int i = 0; i < 10000; i++) {
UUID id = timeBasedGenerator.generate();
synchronized (ids) {
if (!ids.add(id)) {
throw new RuntimeException("Id not unique: " + id);
}
}
}
}
};
ExecutorService executorService = Executors.newFixedThreadPool(5);
for (int i = 0; i < 2; i++) {
executorService.execute(r);
}
executorService.shutdown();
Synchronizing on timeBasedGenerator resolves this.05-15-2012 04:12 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.