在下面的代码中,是否可以再次重用相同的 timer1 对象而不是 timer2 来调用 timertask?
Timer timer1 = new Timer();
timer1.scheduleAtFixedRate(new TimerTask() {
int counter = 0;
@Override
public void run() {
PriorityQueueHandler.getQueueInstance().addToQueue(passengers.get(counter));
counter++;
if(counter == passengers.size()){
counter = 0;
}
}
}, DELAY, ARRIVAL_INTERVAL);
PriorityQueueHandler.getQueueInstance().print();
Timer timer2 = new Timer();
timer2.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
PriorityQueueHandler.getQueueInstance().print();
}
}, DELAY, BOOKING_INTERVAL);