-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServer_a.java
More file actions
78 lines (63 loc) · 2.18 KB
/
WebServer_a.java
File metadata and controls
78 lines (63 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
*
* CS433/533 Demo
*/
import java.io.*;
import java.util.*;
import serverCache.ServerCacheSingleton;
import java.net.*;
public class WebServer_a {
private static ServerSocket welcomeSocket;
public static int THREAD_COUNT = 10;
private Thread[] threads;
private static properties prop;
public static int serverPort = 10000;
public static String WWW_ROOT = util.WS_ROOT;
/* Constructor: starting all threads at once */
public WebServer_a(int serverPort) {
try {
// create server socket
welcomeSocket = new ServerSocket(serverPort);
// System.out.println("server listening at: " + welcomeSocket);
ServerCacheSingleton.init(4096);
// create thread pool
threads = new Thread[THREAD_COUNT];
Service_a service = new Service_a(welcomeSocket, prop, WWW_ROOT);
// start all threads
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(service);
threads[i].start();
}
} catch (Exception e) {
//System.out.println("Server construction failed.");
} // end of catch
} // end of Server
public static void main(String[] args) throws IOException {
properties prop = new properties();
// System.out.println(THREAD_COUNT);
if (args.length > 1) {
prop.config(args[1]);
// System.out.println(THREAD_COUNT);
serverPort = prop.getServerPort();
}
welcomeSocket = new ServerSocket(serverPort);
// System.out.println(THREAD_COUNT);
Service_a service = new Service_a(welcomeSocket, prop, WWW_ROOT);
for (int i = 0; i < THREAD_COUNT; i++) {
Thread thread = new Thread(service);
thread.start();
}
}
// public void run() {
//
// try {
// for (int i = 0; i < threads.length; i++) {
// threads[i].join();
// }
// //System.out.println("All threads finished. Exit");
// } catch (Exception e) {
// // System.out.println("Join errors");
// } // end of catch
//
// }
}