La modificación de un temporizador de retardo oscilación durante el tiempo de ejecución

StackOverflow https://stackoverflow.com/questions/930798

Pregunta

Estoy desarrollando una simulación de cola, utilizando un temporizador Swing para quitar de la cola objetos después de ciertos períodos de tiempo. El intervalo es determinado por mira a escondidas en el siguiente objeto en la cola, conseguir un número entero de ella, y se ajusta el retardo de su correspondiente temporizador.

Este es el fragmento relevante del programa (Nota: _SECONDS_PER_ITEM es una constante definida en otro lugar a 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();

El problema que tengo es que cada cliente, no importa cuántos artículos que tienen, se procesa en un segundo.

¿Hay algún otro método o técnica que debería usar para establecer el retraso?

¿Fue útil?

Solución

Parece que cuando stop()ing un temporizador, el retraso que se utiliza para disparar el próximo evento es el retardo inicial. Por lo tanto, el método correcto para utilizar en el ejemplo anterior, es setInitialDelay():

{
// stop the timer
qTimer[q].stop();

// peek at how many items the customer has, and set the delay.
qTimer[q].setInitialDelay(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();

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top