-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: 유저 프로필 (기본, 소개글) 생성/수정 (#PC-80) #7
Conversation
저도 공통 응답을 넣긴 했는데, 찬호님께 더 디테일한거 같아서 찬호님 꺼로 사용하는게 좋을거 같아요 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
private static final Random RANDOM = new Random(); | ||
|
||
public static String generateNickname() { | ||
String animal = ANIMAL_NAMES.get(RANDOM.nextInt(ANIMAL_NAMES.size())); | ||
int number = RANDOM.nextInt(10000) + 1; | ||
return animal + number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자바 공식문서에 따르면, java.util.Random을 멀티스레드에서 동시에 이용할 때 성능 저하를 보일 수 있다고 합니다.
ThreadLocalRandom을 고려해보는 것은 어떨까요?
아래는 오라클 공식문서의 설명입니다!
the concurrent use of the same java.util.Random instance across threads may encounter contention and consequent poor performance. Consider instead using ThreadLocalRandom in multithreaded designs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JAVA의 Radmom은 시드 값을 기반으로 난수 값을 생성한다고 합니다. 그래서 시드 값이 같으면 같은 난수를 생성하며, 다르면 동일하지 않은 값을 생성합니다. 그래서, Random은 시드 값으로 난수를 생성하고 나면 시드를 업데이트 해야하는데, 여러 개의 쓰레드에서 동시에 업데이트하려고 할 때, 순서를 보장하기 위해 CAS연산을 진행하며 이떄 성능저하가 발생하는 것 같습니다.
ThreadLocalRandom은 Radmon이 여러 쓰레드에게 공유되어 발생했던 문제를, 각 스레드마다 고유한 난수 생성기와 시드를 할당 함으로써 해결한다고 합니다. 그리고 ThreadLocal이란 방식으로 Random을 각 쓰레드에게 배정해주는 방법도 있는 거 같은데, ThreadLcoalRandom 사용법이 더 간단하고 효율적인 것 같습니다.
ThreadLcoalRandom로 수정하겠습니다 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자세한 정보 감사합니다!
고생하셨습니다.
🔗 관련 이슈
티켓: #PC-80
깃이슈: #6
✨ 작업 내용
✅ 체크리스트
📋 참고 사항