Code example for LinkedBlockingDeque

0
package ru.ifmo.ctdev.baidarov.network.server; 
 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.PrintWriter; 
import java.util.concurrent.BlockingDeque; 
import java.util.concurrent.LinkedBlockingDeque; 
 
public class Writer implements Runnable {
    private final BlockingDeque<Result> queue = new LinkedBlockingDeque<>();
    private final File file;
 
    public Writer(File file) {
        this.file = file;
    } 
 
    public void push(Result result) {
        queue.add(result);
    } 
 
    @Override 
    public void run() { 
        try (PrintWriter pw = new PrintWriter(new FileOutputStream(file))) {
            while (!Thread.interrupted()) {
                pw.println(queue.take());