File tree 1 file changed +2
-7
lines changed
11-network-ii/snippets/echoclientserver/src/bg/sofia/uni/fmi/mjt/echo/net/multithreaded
1 file changed +2
-7
lines changed Original file line number Diff line number Diff line change @@ -12,19 +12,15 @@ public class EchoServer {
12
12
private static final int MAX_EXECUTOR_THREADS = 10 ;
13
13
14
14
public static void main (String [] args ) {
15
-
16
- ExecutorService executor = Executors .newFixedThreadPool (MAX_EXECUTOR_THREADS );
17
-
18
15
Thread .currentThread ().setName ("Echo Server Thread" );
19
16
20
- try (ServerSocket serverSocket = new ServerSocket (SERVER_PORT )) {
17
+ try (ServerSocket serverSocket = new ServerSocket (SERVER_PORT );
18
+ ExecutorService executor = Executors .newFixedThreadPool (MAX_EXECUTOR_THREADS );) {
21
19
22
20
System .out .println ("Server started and listening for connect requests" );
23
-
24
21
Socket clientSocket ;
25
22
26
23
while (true ) {
27
-
28
24
// Calling accept() blocks and waits for connection request by a client
29
25
// When a request comes, accept() returns a socket to communicate with this
30
26
// client
@@ -40,7 +36,6 @@ public static void main(String[] args) {
40
36
// new Thread(clientHandler).start();
41
37
executor .execute (clientHandler ); // use a thread pool to launch a thread
42
38
}
43
-
44
39
} catch (IOException e ) {
45
40
throw new RuntimeException ("There is a problem with the server socket" , e );
46
41
}
You can’t perform that action at this time.
0 commit comments