06-02 22:26
Notice
Recent Posts
Recent Comments
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

(주) 망나니 힘집

무난하게 통과해버린 로그인 정보 인스턴스화 시켜서 변수를 전역으로 사용하기 본문

스펙도 쌓니

무난하게 통과해버린 로그인 정보 인스턴스화 시켜서 변수를 전역으로 사용하기

군포망나니 2025. 4. 2. 17:24

저번 ThreadLocal 의 실패 여파로 나를 자극하였숨 

 

근데? 더 간단하게 구현에 성공해버림 

 

일단 싱글톤 패턴에 대해서 공부할 수 있는 기회가 되었숨 

 

 

 일단 만드러유 Bean!! 
public class UserProfile {

private static UserProfile instance = new UserProfile();

    private String loginId; 
     
private UserProfile() {
}

 

// 싱글톤 패턴 !! 
public static UserProfile getInstance() {
if(instance == null) {
instance = new UserProfile(); 
}
return instance;

 

// synchronized  - 멀티쓰레드 환경에서도 안정적이기 위해 사용 
public synchronized void setLoginId(String loginId) {
    this.loginId = loginId;
}
 
    public String getLoginId() {
        return loginId;
    }


}
 

Login 을 하는 클래스 파일에다가 인스턴스를 소환해버림 !! 

 

/**
 * @author dbk
 * @brief UserProfile
 * @brief After inserting UserProfile userProfile = UserProfile.getInstance(); into the desired class, you can use the method  
 */ 
    String id = map.get("idLogin").toString();

    UserProfile userProfile = UserProfile.getInstance();
    
    userProfile.setLoginId(id);  

 

 

설명도 넣어줌 !! 

 

@brief After inserting UserProfile userProfile = UserProfile.getInstance(); into the desired class, you can use the method

 

일단 로그인 ID 를 가져오는 파일에다가 UserProfile userProfile = UserProfile.getInstance(); 삽입해준 후에 

method  를 자유롭게 쓸 수 있숨 

 

근데?? 이게 과연 안전할 지 의문이여........................................ 일단 돌아가긴 함... ㅋ.... 

 

 

 

또한 내가 작성한 것을 표현하기 위해서 참고하였숨 

https://big-brown-bear93.tistory.com/10

 

[주석] 코드 문서화를 위한 주석 규칙 (@param, @return 활용기)

프로젝트 소스를 보다가 이런 주석이 있다. /** * 요청 결과 상세 조회. * * @param request the request * @param commonInfo the common info * @return the req result detail */ 여기서 @param, @return은 무엇? @param 변수를 설명

big-brown-bear93.tistory.com

 

그럼 ㅂㅂ