Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions study/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ handlebars:

server:
tomcat:
accept-count: 2
max-connections: 2
accept-count: 1
max-connections: 1
threads:
min-spare: 2
max: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ public abstract class AbstractController implements Controller {
public void service(HttpRequest httpRequest, HttpResponse httpResponse) {
if (httpRequest.isMethod(HttpMethod.GET)) {
doGet(httpRequest, httpResponse);
return;
}
if (httpRequest.isMethod(HttpMethod.POST)) {
doPost(httpRequest, httpResponse);
return;
}

throw new IllegalArgumentException("유효하지 않은 메소드입니다.");
Expand Down
17 changes: 6 additions & 11 deletions tomcat/src/main/java/org/apache/catalina/connector/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.io.UncheckedIOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.coyote.http11.Http11Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -16,19 +14,16 @@ public class Connector implements Runnable {

private static final int DEFAULT_PORT = 8080;
private static final int DEFAULT_ACCEPT_COUNT = 100;
private static final int DEFAULT_MAX_THREADS = 250;

private final ServerSocket serverSocket;
private final ExecutorService executor;
private boolean stopped;

public Connector() {
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT, DEFAULT_MAX_THREADS);
this(DEFAULT_PORT, DEFAULT_ACCEPT_COUNT);
}

public Connector(final int port, final int acceptCount, final int maxThreads) {
public Connector(final int port, final int acceptCount) {
this.serverSocket = createServerSocket(port, acceptCount);
this.executor = Executors.newFixedThreadPool(maxThreads);
this.stopped = false;
}

Expand All @@ -43,8 +38,10 @@ private ServerSocket createServerSocket(final int port, final int acceptCount) {
}

public void start() {
var thread = new Thread(this);
thread.setDaemon(true);
thread.start();
stopped = false;
executor.execute(this);
log.info("Web Application Server started {} port.", serverSocket.getLocalPort());
}

Expand All @@ -69,7 +66,7 @@ private void process(final Socket connection) {
return;
}
var processor = new Http11Processor(connection);
executor.execute(processor);
new Thread(processor).start();
}

public void stop() {
Expand All @@ -78,8 +75,6 @@ public void stop() {
serverSocket.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
} finally {
executor.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private HttpResponse createResponse(HttpRequest httpRequest) {
HttpResponse httpResponse = new HttpResponse();
try {
handle(httpRequest, httpResponse);
return httpResponse;
} catch (NotFoundException e) {
httpResponse.location(httpRequest, NOT_FOUND_PATH);
} catch (UnauthorizedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public byte[] toResponse() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(httpStatusLine.createStatusLineResponse())
.append(RESPONSE_LINE_DELIMITER)
.append(httpResponseHeader.createHeadersResponse())
.append(RESPONSE_LINE_DELIMITER);
.append(httpResponseHeader.createHeadersResponse());
if (httpResponseBody != null) {
stringBuilder.append(RESPONSE_LINE_DELIMITER)
.append(httpResponseBody.getBody());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.apache.coyote.http11.session;

import com.techcourse.model.User;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Session {

Expand All @@ -13,7 +13,7 @@ public class Session {

public Session(String id) {
this.id = id;
this.attributes = new ConcurrentHashMap<>();
this.attributes = new HashMap<>();
}

public boolean hasAttribute(String name) {
Expand Down