[英]Java retrieve all the elements from a queue until it is empty
I want to implement a Queue of elements in android/java such that, 我想在android / java中实现元素队列 ,
What could be the best Collection to use for this scenario? 在这种情况下,最好的集合是什么? Are there any default callbacks any collection provides which suffice condition 3?
有任何集合提供满足条件3的默认回调吗?
One implementation I can think of is writing a method in my Queue impelementation which is something like 我能想到的一个实现是在Queue实现中编写一种方法,类似于
public static void executeNext() {
Executor element = getFirst();
if (element != null && element.doneExecuting()) {
pop();
}
Executor next = getFirst();
next.execute();
}
which will be called from my Executor
class object (which is an element of my Queue) once the execution finishes 执行完成后,将从我的
Executor
类对象(这是我的Queue的一个元素)中调用该对象
public void onExceutionComplete(){
ExecutionQueue.getInstance().executeNext();
}
Why dont you try to implement a listener, which will keep listening to the queue. 您为什么不尝试实现一个侦听器,它将继续侦听队列。
This will make sure as soon as new entries are in there, they would start getting executed. 这样可以确保一旦有新条目进入,它们就会开始执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.