From c292ff2d9e362437f834592fe71a27ab0b0656cf Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Thu, 25 Jan 2024 20:08:32 +0100 Subject: [PATCH] added non-threaded close() method for logging --- .../dhbwstuttgart/typeinference/unify/TypeUnify2Task.java | 6 +++++- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 7 +++++-- .../typeinference/unify/WriterActiveObject.java | 8 ++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 5ed438db3..03472f656 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -65,6 +65,10 @@ public class TypeUnify2Task extends TypeUnifyTask { } public void closeLogFile() { - logFile.close(); + if(parallel){ + logFile.close(); + }else{ + logFile.closeNonThreaded(); + } } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 902eb3d00..f7bbb96a2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -186,7 +186,6 @@ public class TypeUnifyTask extends RecursiveTask>> { }else{ this.logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream()), pool); } - logFile.write(""); } catch (IOException e) { System.err.println("log-File nicht vorhanden"); @@ -268,7 +267,11 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>()); noOfThread--; - logFile.close(); + if(parallel){ + logFile.close(); + }else{ + logFile.closeNonThreaded(); + } if (isUndefinedPairSetSet(res)) { //fuer debug-Zwecke diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java index 1b7ed7063..ab93d982c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/WriterActiveObject.java @@ -42,4 +42,12 @@ public class WriterActiveObject { throw new RuntimeException(e); } } + + public void closeNonThreaded(){ + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } }