Use LinkedBlockingQueue : LinkedBlockingQueue « JDK 7 « Java
- Java
- JDK 7
- LinkedBlockingQueue
Use LinkedBlockingQueue
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.util.concurrent.LinkedBlockingQueue;
public class Test {
public static void main(String[] args) throws Exception {
LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();
FileOutputStream fos = new FileOutputStream("out.log");
DataOutputStream dos = new DataOutputStream(fos);
while (!queue.isEmpty()) {
dos.writeUTF(queue.take());
}
}
}
Related examples in the same category