private Thread readInThread;
private Thread writeOutThread;
- public SocketPipeMirror() throws IOException {
+ private final String id;
+
+ public SocketPipeMirror(String id) throws IOException {
+ this.id = id;
inPipe = Pipe.open();
outPipe = Pipe.open();
in = Channels.newInputStream(inPipe.source());
} catch (IOException e) {
e.printStackTrace();
}
- }, "Read in");
+ }, "JShell read " + id);
readInThread.start();
writeOutThread = new Thread(() -> {
} catch (IOException e) {
e.printStackTrace();
}
- }, "Write out");
+ }, "JShell write " + id);
writeOutThread.start();
}
@Override
public void close() throws IOException {
// TODO make it more robust
- readInThread.interrupt();
- writeOutThread.interrupt();
+// readInThread.interrupt();
+// writeOutThread.interrupt();
in.close();
out.close();
+ try {
+ readInThread.join();
+ } catch (InterruptedException e) {
+ // silent
+ }
+ try {
+ writeOutThread.join();
+ } catch (InterruptedException e) {
+ // silent
+ }
}
public InputStream getInputStream() {