강의

멘토링

커뮤니티

Inflearn Community Q&A

wnstn0154's profile image
wnstn0154

asked

Spring MVC Part 1 - Core technologies for backend web development

Member Management Web Application Requirements

싱글톤 패턴에 대해

Written on

·

311

0

 private static Map<Long, Member> store = new HashMap<>(); //static 사용

 private static long sequence = 0L; //static 사용

 private static final MemberRepository instance = new MemberRepository();

 public static MemberRepository getInstance() {

 return instance;

 }

이렇게하면 

static 메모리에 store, sequence, instance, getinstance()가 저장이 먼저 되는것 까지는 이해했습니다.

근데 instance는 다시 생성자로 인해서 store, sequece... 등등의 데이터를 다시 static 메모리에 올릴 텐데 그렇다면

instance도 다시 생겨나는 .. 재귀 함수적인 형태가 머리속에 맴돌고 있습니다. 

이런 코드면 재귀함수적으로 실행되는게 아닌가요?

springMVC

Answer 2

2

wnstn0154님의 프로필 이미지
wnstn0154
Questioner

항상 이상한 질문만해대서 죄송합니다..ㅠ . .ㅠ 그래도 꼬박꼬박 답변달아주시는 영한님(? 조교님?).. 그저 빛..

yh님의 프로필 이미지
yh
Instructor

ㅎㅎ 탈룰라님 화이팅!

2

yh님의 프로필 이미지
yh
Instructor

안녕하세요. 탈룰라님^^

static은 인스턴스 생성과 무관하게 static이라는 별도의 메모리 영역에 1번만 포함됩니다.

따라서 재귀적인 모습이 진행되지는 않습니다.

감사합니다.

wnstn0154's profile image
wnstn0154

asked

Ask a question