-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0184b25
refactor: User 클래스 교체
Lujaec 71784ed
feat: 프로필 도메인 설계
Lujaec 3af9bfe
feat: UserNotFound 에러 코드 등록
Lujaec 6e7250c
feat: User 조회 메서드
Lujaec b16b142
feat: 닉네임 랜덤 생성기
Lujaec 3f0d5df
feat: 프로필 생성 기능
Lujaec 31f61e4
feat: 공통 Response 정의
Lujaec cf887ac
feat: 시큐리티 Swagger uri 허용 (#PC-69)
Lujaec ff64d2e
feat: 프로필 정보 (기본정보, 소개) 수정 기능(#PC-80)
Lujaec fe5f8ad
feat: 프로필 정보 (기본정보, 소개) 수정 기능(#PC-80)
Lujaec 32cb33a
feat: 프로필 정보 (기본정보, 소개) 수정 API (#PC-80)
Lujaec 1a8f433
test: 프로필 수정 (기본 정보, 소개) 테스트 (#PC-80)
Lujaec 58d3222
feat: 프로필 조회 (기본 정보, 소개) (#PC-80)
Lujaec 69df26d
feat: 프로필 조회 swagger (#PC-80)
Lujaec a98eee2
fix: Random을 ThreadLocalRandom으로 수정
Lujaec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
api/src/main/java/org/yapp/domain/profile/application/util/NickNameGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.yapp.domain.profile.application.util; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class NickNameGenerator { | ||
// 한글 동물 이름 10가지 | ||
private static final List<String> ANIMAL_NAMES = | ||
List.of("사자", "호랑이", "곰", "독수리", "늑대", "판다", "여우", "사슴", "토끼", "돌고래"); | ||
|
||
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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
자세한 정보 감사합니다!
고생하셨습니다.