Browse Source

What's the point of threads if the program can only handle one request at a time?

Mitch Taylor 6 years ago
parent
commit
7ab4252f9d

+ 14
- 16
Client/src/main/java/SimpleShell.java View File

21
         BufferedReader console = new BufferedReader
21
         BufferedReader console = new BufferedReader
22
                 (new InputStreamReader(System.in));
22
                 (new InputStreamReader(System.in));
23
 
23
 
24
-        ObjectMapper mapper = new ObjectMapper();
25
         ProcessBuilder pb = new ProcessBuilder();
24
         ProcessBuilder pb = new ProcessBuilder();
26
         List<String> history = new ArrayList<String>();
25
         List<String> history = new ArrayList<String>();
27
         int index = 0;
26
         int index = 0;
90
                 }
89
                 }
91
 
90
 
92
                 // wait, wait, what curiousness is this?
91
                 // wait, wait, what curiousness is this?
93
-                Process process = pb.start();
94
-
95
-                //obtain the input stream
96
-                InputStream is = process.getInputStream();
97
-                InputStreamReader isr = new InputStreamReader(is);
98
-                BufferedReader br = new BufferedReader(isr);
99
-
100
-                //read output of the process
101
-                String line;
102
-                while ((line = br.readLine()) != null)
103
-                    System.out.println(line);
104
-                br.close();
105
-
106
-
92
+//                Process process = pb.start();
93
+//
94
+//                //obtain the input stream
95
+//                InputStream is = process.getInputStream();
96
+//                InputStreamReader isr = new InputStreamReader(is);
97
+//                BufferedReader br = new BufferedReader(isr);
98
+//
99
+//                //read output of the process
100
+//                String line;
101
+//                while ((line = br.readLine()) != null)
102
+//                    System.out.println(line);
103
+//                br.close();
104
+                ThreadCall threadCall = new ThreadCall();
105
+                threadCall.run(pb);
107
             }
106
             }
108
 
107
 
109
             //catch ioexception, output appropriate message, resume waiting for input
108
             //catch ioexception, output appropriate message, resume waiting for input
121
 
120
 
122
         }
121
         }
123
 
122
 
124
-
125
     }
123
     }
126
 
124
 
127
 }
125
 }

+ 21
- 0
Client/src/main/java/ThreadCall.java View File

1
+import java.io.BufferedReader;
2
+import java.io.IOException;
3
+import java.io.InputStream;
4
+import java.io.InputStreamReader;
5
+
6
+public class ThreadCall extends Thread{
7
+
8
+    public void run(ProcessBuilder pb) throws IOException {
9
+        Process process = pb.start();
10
+        InputStream is = process.getInputStream();
11
+        InputStreamReader isr = new InputStreamReader(is);
12
+        BufferedReader br = new BufferedReader(isr);
13
+
14
+        //read output of the process
15
+        String line;
16
+        while ((line = br.readLine()) != null)
17
+            System.out.println(line);
18
+        br.close();
19
+    }
20
+
21
+}

+ 0
- 2
Client/src/main/java/YouAreEll.java View File

1
 import com.fasterxml.jackson.databind.ObjectMapper;
1
 import com.fasterxml.jackson.databind.ObjectMapper;
2
 import okhttp3.*;
2
 import okhttp3.*;
3
 
3
 
4
-import java.io.IOException;
5
-
6
 public class YouAreEll {
4
 public class YouAreEll {
7
 
5
 
8
     private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
6
     private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");