forked from JavaTX/JavaCompilerCore
added class for thread safe writing in logfiles
This commit is contained in:
parent
b806fa88ff
commit
28969e7931
@ -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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user