I have an ArrayBlockingQueue<String> queue;
and an Author
object puts elements in there:
public static final String END = "db8097f51282a0188e988d6bfa994430258e24ce";
[...]
for (String text : texts) {
queue.put(text);
Thread.sleep(300);
}
queue.put(END);
and a Printer
objects which takes elements from the qeue and prints them on the console:
String text;
do {
text = queue.take();
if (!text.equals(Author.END))
System.out.println(text);
} while (tekst != Author.END);
I wanted inform Printer
object that there will be no more elements put into the qeue. I cannot pass null
into ArrayBlockingQueue
so I decided to pass very unusual String
inside. I think it is bad solution.
Can I somehow close the ArrayBlockingQueue
?
your solution seems fine. Two points to consider:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.