import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
class Main {
private static final int THREAD_COUNT = 8;
private static final SecureRandom RANDOM = new SecureRandom();
private static AtomicLong objectCount = new AtomicLong();
private static void updateCount(String thread, long count) {
System.out.printf("%s: %,d | Totally: %,d%n", thread, count, objectCount.addAndGet(count));
}
public static void main(String[] args) {
for (int i = 0; i < THREAD_COUNT; i++) {
Thread thread = new Thread(() -> {
List<Object> objects = new LinkedList<>();
for (long j = 1;; j++) {
try {
BigInteger object = new BigInteger(100, RANDOM);
if (j % 100_000 == 0) {
updateCount(Thread.currentThread().getName(), j);
}
objects.add(object);
} finally {
continue;
}
}
});
thread.start();
}
}
}