Procházet zdrojové kódy

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

Mitch Taylor před 6 roky
rodič
revize
7ab4252f9d

+ 14
- 16
Client/src/main/java/SimpleShell.java Zobrazit soubor

@@ -21,7 +21,6 @@ public class SimpleShell {
21 21
         BufferedReader console = new BufferedReader
22 22
                 (new InputStreamReader(System.in));
23 23
 
24
-        ObjectMapper mapper = new ObjectMapper();
25 24
         ProcessBuilder pb = new ProcessBuilder();
26 25
         List<String> history = new ArrayList<String>();
27 26
         int index = 0;
@@ -90,20 +89,20 @@ public class SimpleShell {
90 89
                 }
91 90
 
92 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 108
             //catch ioexception, output appropriate message, resume waiting for input
@@ -121,7 +120,6 @@ public class SimpleShell {
121 120
 
122 121
         }
123 122
 
124
-
125 123
     }
126 124
 
127 125
 }

+ 21
- 0
Client/src/main/java/ThreadCall.java Zobrazit soubor

@@ -0,0 +1,21 @@
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 Zobrazit soubor

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