我正在开发一个队列模拟,使用 Swing Timer 在一定时间后使对象出队。间隔是通过查看队列中的下一个对象,从中获取一个整数,并设置其相应计时器的延迟来确定的。
这是程序中的相关片段(注意:_SECONDS_PER_ITEM
是在其他地方定义的常量2000
):
// stop the timer
qTimer[q].stop();
// peek at how many items the customer has, and set the delay.
qTimer[q].setDelay(customerQueue[q].peek().getItems()*_SECONDS_PER_ITEM);
// the next time around, this method will see the flag, and dequeue the customer.
working[q] = true;
// denote that the customer is active on the UI.
lblCustomer[q][0].setBorder(new LineBorder(Color.RED, 2));
// start the timer.
qTimer[q].start();
我遇到的问题是每个客户,无论他们有多少物品,都会在一秒钟内得到处理。
我应该使用其他方法或技术来设置延迟吗?