-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServer_c.java
More file actions
59 lines (46 loc) · 1.69 KB
/
WebServer_c.java
File metadata and controls
59 lines (46 loc) · 1.69 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import serverCache.ServerCacheSingleton;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ningluo
*/
public class WebServer_c {
private static ServerSocket welcomeSocket =null;
public final static int THREAD_COUNT = 10;
private static properties prop;
public static int serverPort = 10000;
public static String WWW_ROOT = util.WS_ROOT;
public static void main(String[] args) throws IOException, Exception {
prop = new properties();
if (args.length > 1) {
prop.config(args[1]);
serverPort = prop.getServerPort();
}
try {
welcomeSocket= new ServerSocket(serverPort);
//System.out.println("Time server listens at port: " + serverPort);
ServerCacheSingleton.init(prop.getCacheSize());
// Create Java Executor Pool
TimeServerHandlerExecutePool myExecutor
= new TimeServerHandlerExecutePool(prop.getpoolSize(),10000);
Socket socket = null;
while (true) {
socket = welcomeSocket.accept();
myExecutor.execute(new WebRequestHandler(socket,prop.getNameMap()));
} // end of while
} finally {
if ( welcomeSocket != null) {
// System.out.println("The time server closes.");
welcomeSocket.close();
welcomeSocket = null;
}
} // end of finally
} // end of main
}