Skip to content

[Tomcat 구현하기 - 4단계] 리건(이한길) 미션 제출합니다.#720

Merged
lilychoibb merged 41 commits intowoowacourse:hangilleefrom
hangillee:step4
Sep 16, 2024
Merged

[Tomcat 구현하기 - 4단계] 리건(이한길) 미션 제출합니다.#720
lilychoibb merged 41 commits intowoowacourse:hangilleefrom
hangillee:step4

Conversation

@hangillee
Copy link
Copy Markdown
Member

안녕하세요, 릴리! 👋
미션 잘 마무리하셨나요?

미션 4단계 테스트는 어떻게 짜야할지 고민이 들었습니다.
뭔가 Java 라이브러리에 대한 도전 같다는 생각도 드네요.

리뷰 잘 부탁드립니다!

p.s. 혹시 마지막 리뷰의 Test에 필요한 요청 Header만 추리기가 어떤 걸 말씀하시는 걸까요? 전 모든 헤더가 필요하다고 생각됩니다..

@hangillee hangillee self-assigned this Sep 13, 2024
Copy link
Copy Markdown
Member

@lilychoibb lilychoibb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 리건 🤗~
미션 진행하느라 고생 많으셨어요!
혹시 /com.techcourse.controller 의 FrontController 에서 컴파일 에러가 나는데, 확인해주실 수 있나요? 해당 패키지에 /org.apache.catalina.controller 에 있는 클래스와 중복되는 클래스도 있는 것 같아서 같이 봐주시면 좋을 것 같아요!

4단계 자체에 대한 Files changed 는 많지 않아서 학습 위주의 질문을 남겨봤습니다.
3단계 리뷰 반영도 꼼꼼히 해주셔서 좋네요👍

저도 4단계 테스트를 아직 어떻게 해야할지 감을 못 잡고 있는데, Java 라이브러리에 대한 도전이라고 느끼셨다니 동감합니다😇
앗 그리고 Test에 필요한 요청 Header만 추리기 는 Host 나 Connection 같은 헤더는 꼭 없어도 테스트가 가능하다고 생각해서 말씀드렸던 부분인데, 필요하다고 생각하시면 리건 방식도 좋습니다!


// 올바른 값으로 바꿔서 테스트를 통과시키자.
final int expectedPoolSize = 0;
final int expectedPoolSize = 3;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newFixedThreadPool()newCachedThreadPool() 의 차이는 무엇인가요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newFixedThreadPool()은 초기 스레드 수 0, 코어 스레드 수와 최대 스레드 수는 인자로 전달된 값만큼 설정된 고정 크기 스레드 풀을 생성하는 메소드입니다. newCachedThreadPool()은 초기 스레드 수 0, 코어 스레드 수 0, 최대 스레드 수는 정수형 최대값으로 설정된 가변 크기 스레드 풀을 생성하는 메소드입니다.

여기서 코어 스레드 수는 기준 시간(60초) 이후, 유휴 상태에 놓인 스레드를 회수하지 않고 유지할 개수를 의미합니다. 따라서, FixedThreadPool은 항상 생성된 스레드가 고정된 크기만큼 유지되지만, CachedThreadPool은 매번 요청이 들어올 때마다 새로운 스레드를 생성하고 60초 이상 사용되지 않으면 스레드 풀에서 제거됩니다. 다르게 말하면 60초 안쪽으로 작업이 완료되면 새로운 요청을 바로 처리할 수 있는, 스레드를 캐싱할 수 있는 스레드 풀입니다.

Comment on lines +15 to +21
if (users.contains(user)) {
return;
}
synchronized (this) {
if (!users.contains(user)) {
users.add(user);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼꼼히 처리해주셨네요 👍

Comment on lines +9 to +10
accept-count: 2
max-connections: 2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 값은 무엇을 의미하나요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept-countmax-connections 이상으로 웹 서버에 연결 요청이 들어왔을 때, 큐에서 대기할 수 있는 소켓 연결의 개수에 대한 설정이며, max-connections는 동시에 웹 서버와 연결을 맺고 있을 수 있는(처리할 수 있는) 최대 개수에 대한 설정입니다.

public class SessionManager {

private static final Map<String, Session> SESSIONS = new HashMap<>();
private static final Map<String, Session> SESSIONS = new ConcurrentHashMap<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concurrent Collections 는 왜 사용하나요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멀티 스레드 환경에서 추가와 삭제 같은 element 변경 작업 중, 동시성 문제가 발생할 수 있기 때문입니다. 대표적으로 스레드 간섭과 메모리 일관성 오류 같은 문제가 있습니다. 이를 막기 위해 Concurrent Collections를 활용합니다.

Comment on lines +22 to +27
public static FileType parseFilenameExtension(final String path) {
return Arrays.stream(FileType.values())
.filter(fileType -> path.endsWith(fileType.extension))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 파일 확장자입니다."));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훨씬 깔끔해졌네요👍

private int sum = 0;

public void calculate() {
public synchronized void calculate() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 키워드를 붙이면 테스트가 왜 통과할까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synchronized 키워드는 어느 한 스레드가 해당 메소드를 호출했을 때, 다른 스레드가 호출할 수 없기 때문에 스레드 간섭이 발생하지 않습니다. 따라서 테스트가 통과할 수 있었습니다.

}

public void stop() {
executorService.shutdown();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

Comment on lines +26 to +28
public static int getSize() {
return SESSIONS.size();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 메서드는 왜 추가하셨나요? (테스트 하려고 했던 노고의 흔적..?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다.. 단순히 테스트를 위한 메소드였습니다..

Copy link
Copy Markdown
Member

@lilychoibb lilychoibb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 리건 🙂
리뷰 잘 반영해주셨네요!
4단계 학습 요구사항도 잘 충족된 것 같아 이만 머지할게요 :)
고생 많으셨습니다〰️

@lilychoibb lilychoibb merged commit 702bd31 into woowacourse:hangillee Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants