File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
src/main/java/org/example Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 1
1
package org .example ;
2
2
3
- import org .example .calculator .domain .Calculator ;
4
- import org .example .calculator .domain .PositiveNumber ;
5
3
import org .slf4j .Logger ;
6
4
import org .slf4j .LoggerFactory ;
7
5
8
- import java .io .* ;
6
+ import java .io .IOException ;
9
7
import java .net .ServerSocket ;
10
8
import java .net .Socket ;
11
- import java .nio .charset .StandardCharsets ;
9
+ import java .util .concurrent .ExecutorService ;
10
+ import java .util .concurrent .Executors ;
12
11
13
12
public class CustomWebApplicationServer {
14
13
private final int port ;
15
14
15
+ private final ExecutorService executorService = Executors .newFixedThreadPool (10 );
16
+
16
17
private static final Logger logger = LoggerFactory .getLogger (CustomWebApplicationServer .class );
17
18
18
19
public CustomWebApplicationServer (int port ) {
@@ -30,9 +31,9 @@ public void start() throws IOException {
30
31
logger .info ("[CustomWebApplicationServer] client connected!" );
31
32
32
33
/**
33
- * Step2 - 사용자 요청이 들어올 때마다 Thread를 새로 생성해서 사용자 요청을 처리하도록 한다.
34
+ * Step3 - Thread Pool을 적용해 안정적인 서비스가 가능하도록 한다.
34
35
*/
35
- new Thread (new ClientRequestHandler (clientSocket )). start ( );
36
+ executorService . execute (new ClientRequestHandler (clientSocket ));
36
37
}
37
38
}
38
39
}
You can’t perform that action at this time.
0 commit comments