Swing Timer を使用して一定時間後にオブジェクトをデキューする Queue シミュレーションを開発しています。間隔は、キュー内の次のオブジェクトを調べ、そこから整数を取得し、対応するタイマーの遅延を設定することによって決定されます。
プログラムからの関連するスニペットは次のとおりです (注:_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();
私が抱えている問題は、アイテムの数に関係なく、すべての顧客が 1 秒で処理されることです。
遅延を設定するために使用する必要がある他の方法または手法はありますか?