-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
내 개인 맥에서
2000 개 스레드에서 백만까지 올릴 때 -> 120ms
1000 개 스레드에서 백만까지 올릴 때 -> 100ms
500 개 스레드에서 백만까지 올릴 때 -> 80ms
100 개 스레드에서 백만까지 올릴 때 -> 50ms
5 개 스레드에서 백만까지 올릴 때 -> 30ms
100개의 스레드라면 1초동안 2천만개 카운트 가능
@SneakyThrows
public static void main(String[] args) {
var started = System.currentTimeMillis();
AtomicInteger atomic = new AtomicInteger();
int threadCount = 2000;
Thread[] threads = new Thread[threadCount];
for (int i=0; i<threadCount; ++i) {
threads[i] = new Thread(() -> {
while (atomic.incrementAndGet() <= 1000000) {
}
});
threads[i].start();
}
Arrays.stream(threads).forEach(t -> {
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
var ended = System.currentTimeMillis();
System.out.println(ended - started);
System.out.println(atomic.get());
}Metadata
Metadata
Assignees
Labels
No labels