面对一个带有此代码的项目:
public class IndexUpdater implements Runnable {
@Override
public void run() {
final AtomicInteger count = new AtomicInteger(0);
FindIterable<Document> iterable = mongoService.getDocuments(entryMeta, null, "guid");
iterable.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
count.incrementAndGet();
// A lot of code....
if (count.get() / 100 * 100 == count.get()) {
LOG.info(String.format("Processing: %s", count.get()));
}
}
});
}
}
这里我对三行代码感兴趣:
if (count.get() / 100 * 100 == count.get()) {
LOG.info(String.format("Processing: %s", count.get()));
}
考虑到多线程和 AtomicInteger 变量的类型,这种情况是否有意义?或者这是一个毫无意义的检查?有趣的是,IntellijIdea 并没有强调这种结构毫无意义。