added class for thread safe writing in logfiles

This commit is contained in:
NoName11234 2024-01-20 23:01:21 +01:00
parent b806fa88ff
commit 28969e7931

View File

@ -0,0 +1,24 @@
package de.dhbwstuttgart.typeinference.unify;
import java.io.IOException;
import java.io.Writer;
import java.util.concurrent.ForkJoinPool;
public class WriterActiveObject {
private Writer writer;
private ForkJoinPool pool = new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
public WriterActiveObject(Writer writer){
this.writer = writer;
}
public void write(String message){
pool.execute(()->{
try {
writer.write(message);
} catch (IOException e) {
System.out.println(e.getMessage());
}
});
}
}