MCPcopy Create free account
hub / github.com/deepu105/concurrency-benchmarks / run

Method run

javaws/src/JavaHTTPServer.java:28–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26
27 public ServerThread(Socket socket, int count) {
28 this.socket = socket;
29 this.count = count;
30 }
31
32 @Override
33 public void run() {
34 var file = new File("hello.html");
35 try (
36 // get the input stream
37 var in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
38 // get character output stream to client (for headers)
39 var out = new PrintWriter(socket.getOutputStream());
40 // get binary output stream to client (for requested data)
41 var dataOut = new BufferedOutputStream(socket.getOutputStream());
42 var fileIn = new FileInputStream(file)
43 ) {
44 // add 2 second delay to every 10th request
45 if (count % 10 == 0) {
46 System.out.println("Adding delay. Count: " + count);
47 Thread.sleep(2000);
48 }
49
50 // read the request first to avoid connection reset errors
51 while (true) {
52 String requestLine = in.readLine();
53 if (requestLine == null || requestLine.length() == 0) {
54 break;
55 }
56 }
57
58 // read the HTML file
59 var fileLength = (int) file.length();
60 var fileData = new byte[fileLength];
61 fileIn.read(fileData);
62
63 var contentMimeType = "text/html";

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected